summaryrefslogtreecommitdiffstats
path: root/lib/tolua++/src/bin/lua
diff options
context:
space:
mode:
authorTycho <work.tycho+git@gmail.com>2014-03-15 14:45:26 +0100
committerTycho <work.tycho+git@gmail.com>2014-03-15 14:45:26 +0100
commit2e9fe777e425e65d733110247e73c1d9fb25ab1c (patch)
tree595c98abe3ecc64b56d03fd8ca141c7c68d3f47e /lib/tolua++/src/bin/lua
parentFixed a couple of unneeded returns in ProtoProxy (diff)
downloadcuberite-2e9fe777e425e65d733110247e73c1d9fb25ab1c.tar
cuberite-2e9fe777e425e65d733110247e73c1d9fb25ab1c.tar.gz
cuberite-2e9fe777e425e65d733110247e73c1d9fb25ab1c.tar.bz2
cuberite-2e9fe777e425e65d733110247e73c1d9fb25ab1c.tar.lz
cuberite-2e9fe777e425e65d733110247e73c1d9fb25ab1c.tar.xz
cuberite-2e9fe777e425e65d733110247e73c1d9fb25ab1c.tar.zst
cuberite-2e9fe777e425e65d733110247e73c1d9fb25ab1c.zip
Diffstat (limited to 'lib/tolua++/src/bin/lua')
-rw-r--r--lib/tolua++/src/bin/lua/enumerate.lua78
-rw-r--r--lib/tolua++/src/bin/lua/function.lua1
2 files changed, 55 insertions, 24 deletions
diff --git a/lib/tolua++/src/bin/lua/enumerate.lua b/lib/tolua++/src/bin/lua/enumerate.lua
index 99fe74629..5f0dedfe1 100644
--- a/lib/tolua++/src/bin/lua/enumerate.lua
+++ b/lib/tolua++/src/bin/lua/enumerate.lua
@@ -48,6 +48,21 @@ function classEnumerate:print (ident,close)
print(ident.."}"..close)
end
+_global_output_enums = {}
+
+-- write support code
+function classEnumerate:supcode ()
+ if _global_output_enums[self.name] ~= nil then
+ _global_output_enums[self.name] = 1
+ output("int tolua_is" .. self.name .. " (lua_State* L, int lo, int def, tolua_Error* err)")
+ output("{")
+ output("if (!tolua_isnumber(L,lo,def,err)) return 0;")
+ output("int val = tolua_tonumber(L,lo,def);")
+ output("return val >= " .. self.min .. " && val <= " ..self.max .. ";")
+ output("}")
+ end
+end
+
-- Internal constructor
function _Enumerate (t,varname)
setmetatable(t,classEnumerate)
@@ -67,40 +82,57 @@ function _Enumerate (t,varname)
t.access = parent.curr_member_access
t.global_access = t:check_public_access()
end
-return t
+ return t
end
-- Constructor
-- Expects a string representing the enumerate body
function Enumerate (n,b,varname)
b = string.gsub(b, ",[%s\n]*}", "\n}") -- eliminate last ','
- local t = split(strsub(b,2,-2),',') -- eliminate braces
- local i = 1
- local e = {n=0}
- while t[i] do
- local tt = split(t[i],'=') -- discard initial value
- e.n = e.n + 1
- e[e.n] = tt[1]
- i = i+1
- end
- -- set lua names
- i = 1
- e.lnames = {}
- local ns = getcurrnamespace()
- while e[i] do
- local t = split(e[i],'@')
- e[i] = t[1]
+ local t = split(strsub(b,2,-2),',') -- eliminate braces
+ local i = 1
+ local e = {n=0}
+ local value = 0
+ local min = 0
+ local max = 0
+ while t[i] do
+ local tt = split(t[i],'=') -- discard initial value
+ e.n = e.n + 1
+ e[e.n] = tt[1]
+ tt[2] = tonumber(tt[2])
+ if tt[2] == nil then
+ tt[2] = value
+ end
+ value = tt[2] + 1 -- advance the selected value
+ if tt[2] > max then
+ max = tt[2]
+ end
+ if tt[2] < min then
+ min = tt[2]
+ end
+ i = i+1
+ end
+ -- set lua names
+ i = 1
+ e.lnames = {}
+ local ns = getcurrnamespace()
+ while e[i] do
+ local t = split(e[i],'@')
+ e[i] = t[1]
if not t[2] then
- t[2] = applyrenaming(t[1])
+ t[2] = applyrenaming(t[1])
end
- e.lnames[i] = t[2] or t[1]
- _global_enums[ ns..e[i] ] = (ns..e[i])
- i = i+1
- end
+ e.lnames[i] = t[2] or t[1]
+ _global_enums[ ns..e[i] ] = (ns..e[i])
+ i = i+1
+ end
e.name = n
+ e.min = min
+ e.max = max
if n ~= "" then
Typedef("int "..n)
+ _is_functions[n] = "tolua_is" .. n
end
- return _Enumerate(e, varname)
+ return _Enumerate(e, varname)
end
diff --git a/lib/tolua++/src/bin/lua/function.lua b/lib/tolua++/src/bin/lua/function.lua
index 2358e9ff7..7120fb063 100644
--- a/lib/tolua++/src/bin/lua/function.lua
+++ b/lib/tolua++/src/bin/lua/function.lua
@@ -50,7 +50,6 @@ end
-- Write binding function
-- Outputs C/C++ binding function.
function classFunction:supcode (local_constructor)
-
local overload = strsub(self.cname,-2,-1) - 1 -- indicate overloaded func
local nret = 0 -- number of returned values
local class = self:inclass()