diff options
author | Tycho <work.tycho+git@gmail.com> | 2014-03-19 20:38:00 +0100 |
---|---|---|
committer | Tycho <work.tycho+git@gmail.com> | 2014-03-19 20:38:00 +0100 |
commit | 6a3fe7adcc2a3855a574dbfc2bb79c86e7539f26 (patch) | |
tree | db269080d2bb4ffb20a42cc95490d9886fbbd560 /lib/tolua++/src/bin/lua | |
parent | Merge branch 'master' into unreachable (diff) | |
download | cuberite-6a3fe7adcc2a3855a574dbfc2bb79c86e7539f26.tar cuberite-6a3fe7adcc2a3855a574dbfc2bb79c86e7539f26.tar.gz cuberite-6a3fe7adcc2a3855a574dbfc2bb79c86e7539f26.tar.bz2 cuberite-6a3fe7adcc2a3855a574dbfc2bb79c86e7539f26.tar.lz cuberite-6a3fe7adcc2a3855a574dbfc2bb79c86e7539f26.tar.xz cuberite-6a3fe7adcc2a3855a574dbfc2bb79c86e7539f26.tar.zst cuberite-6a3fe7adcc2a3855a574dbfc2bb79c86e7539f26.zip |
Diffstat (limited to 'lib/tolua++/src/bin/lua')
-rw-r--r-- | lib/tolua++/src/bin/lua/basic.lua | 15 | ||||
-rw-r--r-- | lib/tolua++/src/bin/lua/declaration.lua | 2 | ||||
-rw-r--r-- | lib/tolua++/src/bin/lua/enumerate.lua | 8 | ||||
-rw-r--r-- | lib/tolua++/src/bin/lua/function.lua | 10 |
4 files changed, 28 insertions, 7 deletions
diff --git a/lib/tolua++/src/bin/lua/basic.lua b/lib/tolua++/src/bin/lua/basic.lua index d195f6dec..b5788f2be 100644 --- a/lib/tolua++/src/bin/lua/basic.lua +++ b/lib/tolua++/src/bin/lua/basic.lua @@ -145,12 +145,14 @@ function typevar(type) end end +-- is enum +function isenum (type) + return _enums[type] +end + -- check if basic type function isbasic (type) local t = gsub(type,'const ','') - if _enum_is_functions[t] then - return nil - end local m,t = applytypedef('', t) local b = _basic[t] if b then @@ -385,7 +387,7 @@ end _push_functions = {} _is_functions = {} -_enum_is_functions = {} +_enums = {} _to_functions = {} _base_push_functions = {} @@ -414,5 +416,8 @@ function get_to_function(t) end function get_is_function(t) - return _enum_is_functions[t] or _is_functions[t] or search_base(t, _base_is_functions) or "tolua_isusertype" + if _enums[t] then + return "tolua_is" .. t + end + return _is_functions[t] or search_base(t, _base_is_functions) or "tolua_isusertype" end diff --git a/lib/tolua++/src/bin/lua/declaration.lua b/lib/tolua++/src/bin/lua/declaration.lua index 73bbe910e..5a2adfed9 100644 --- a/lib/tolua++/src/bin/lua/declaration.lua +++ b/lib/tolua++/src/bin/lua/declaration.lua @@ -229,6 +229,8 @@ function classDeclaration:outchecktype (narg) --end elseif t then return '!tolua_is'..t..'(tolua_S,'..narg..','..def..',&tolua_err)' + elseif isenum(self.type) then + return '!tolua_is'..self.type..'(tolua_S,'..narg..','..def..',&tolua_err)' else local is_func = get_is_function(self.type) if self.ptr == '&' or self.ptr == '' then diff --git a/lib/tolua++/src/bin/lua/enumerate.lua b/lib/tolua++/src/bin/lua/enumerate.lua index d5d4426cf..ef3a9574c 100644 --- a/lib/tolua++/src/bin/lua/enumerate.lua +++ b/lib/tolua++/src/bin/lua/enumerate.lua @@ -48,13 +48,17 @@ function classEnumerate:print (ident,close) print(ident.."}"..close) end +function emitenumprototype(type) + output("int tolua_is" .. string.gsub(type,"::","_") .. " (lua_State* L, int lo, const char * type, int def, tolua_Error* err);") +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("lua_Number tolua_is" .. self.name .. " (lua_State* L, int lo, int def, tolua_Error* err)") + output("int tolua_is" .. string.gsub(self.name,"::","_") .. " (lua_State* L, int lo, const char * type, int def, tolua_Error* err)") output("{") output("if (!tolua_isnumber(L,lo,def,err)) return 0;") output("lua_Number val = tolua_tonumber(L,lo,def);") @@ -130,7 +134,7 @@ function Enumerate (n,b,varname) e.min = min e.max = max if n ~= "" then - _enum_is_functions[n] = ("tolua_is" .. n) + _enums[n] = 1 Typedef("int "..n) end return _Enumerate(e, varname) diff --git a/lib/tolua++/src/bin/lua/function.lua b/lib/tolua++/src/bin/lua/function.lua index 7120fb063..ad1ab4225 100644 --- a/lib/tolua++/src/bin/lua/function.lua +++ b/lib/tolua++/src/bin/lua/function.lua @@ -54,6 +54,16 @@ function classFunction:supcode (local_constructor) local nret = 0 -- number of returned values local class = self:inclass() local _,_,static = strfind(self.mod,'^%s*(static)') + -- prototypes for enum functions + if self.args[1].type ~= 'void' then + local i=1 + while self.args[i] do + if isenum(self.args[i].type) then + emitenumprototype(self.args[i].type) + end + i = i+1 + end + end if class then if self.name == 'new' and self.parent.flags.pure_virtual then |