summaryrefslogtreecommitdiffstats
path: root/lib/tolua++/src/bin/lua/compat-5.1.lua
blob: c0a3ec38841fefbc644ccc662a7d8430c2a9d1af (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
if string.find(_VERSION, "5%.0") then
	return
end

-- "loadfile"
local function pp_dofile(path)

	local loaded = false
	local getfile = function()

		if loaded then
			return
		else
			local file,err = io.open(path)
			if not file then
				error("error loading file "..path..": "..err)
			end
			local ret = file:read("*a")
			file:close()

			ret = string.gsub(ret, "%.%.%.%s*%)$", "...) local arg = {n=select('#', ...), ...};")
			
			loaded = true
			return ret
		end
	end

	local f, err = load(getfile, path)
	if not f then
		error("error loading file " .. path .. ": " .. err)
	end
	return f()
end

old_dofile = dofile
dofile = pp_dofile


-- string.gsub
--[[
local ogsub = string.gsub
local function compgsub(a,b,c,d)
  if type(c) == "function" then
    local oc = c
    c = function (...) return oc(...) or '' end
  end
  return ogsub(a,b,c,d)
end
string.repl = ogsub
--]]

--string.gsub = compgsub




-- Lua 5.2+ and LuaJit don't have string.gfind(). Use string.gmatch() instead:
if not(string.gfind) then
	string.gfind = string.gmatch
end