diff options
Diffstat (limited to 'lib/tolua++/src/bin/lua')
-rw-r--r-- | lib/tolua++/src/bin/lua/basic.lua | 11 | ||||
-rw-r--r-- | lib/tolua++/src/bin/lua/declaration.lua | 2 | ||||
-rw-r--r-- | lib/tolua++/src/bin/lua/enumerate.lua | 14 | ||||
-rw-r--r-- | lib/tolua++/src/bin/lua/function.lua | 10 |
4 files changed, 32 insertions, 5 deletions
diff --git a/lib/tolua++/src/bin/lua/basic.lua b/lib/tolua++/src/bin/lua/basic.lua index 10cb5b18b..4bff5276b 100644 --- a/lib/tolua++/src/bin/lua/basic.lua +++ b/lib/tolua++/src/bin/lua/basic.lua @@ -67,6 +67,8 @@ _global_enums = {} -- List of auto renaming _renaming = {} + +_enums = {} function appendrenaming (s) local b,e,old,new = strfind(s,"%s*(.-)%s*@%s*(.-)%s*$") if not b then @@ -146,6 +148,11 @@ function typevar(type) end end +-- is enum +function isenumtype (type) + return _enums[type] +end + -- check if basic type function isbasic (type) local t = gsub(type,'const ','') @@ -383,6 +390,7 @@ end _push_functions = {} _is_functions = {} +_enums = {} _to_functions = {} _base_push_functions = {} @@ -411,5 +419,8 @@ function get_to_function(t) end function get_is_function(t) + 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..26ceeba22 100644 --- a/lib/tolua++/src/bin/lua/declaration.lua +++ b/lib/tolua++/src/bin/lua/declaration.lua @@ -227,6 +227,8 @@ function classDeclaration:outchecktype (narg) --else return '!tolua_istable(tolua_S,'..narg..',0,&tolua_err)' --end + elseif isenumtype(self.type) ~= nil then + return '!tolua_is'..self.type..'(tolua_S,'..narg..','..def..',&tolua_err)' elseif t then return '!tolua_is'..t..'(tolua_S,'..narg..','..def..',&tolua_err)' else diff --git a/lib/tolua++/src/bin/lua/enumerate.lua b/lib/tolua++/src/bin/lua/enumerate.lua index 5f0dedfe1..09b22a094 100644 --- a/lib/tolua++/src/bin/lua/enumerate.lua +++ b/lib/tolua++/src/bin/lua/enumerate.lua @@ -48,17 +48,21 @@ function classEnumerate:print (ident,close) print(ident.."}"..close) end +function emitenumprototype(type) + output("int tolua_is" .. string.gsub(type,"::","_") .. " (lua_State* L, int lo, int def, tolua_Error* err);") +end + _global_output_enums = {} -- write support code function classEnumerate:supcode () - if _global_output_enums[self.name] ~= nil then + 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("int tolua_is" .. string.gsub(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("lua_Number val = tolua_tonumber(L,lo,def);") + output("return val >= " .. self.min .. ".0 && val <= " ..self.max .. ".0;") output("}") end end @@ -130,8 +134,8 @@ function Enumerate (n,b,varname) e.min = min e.max = max if n ~= "" then + _enums[n] = true Typedef("int "..n) - _is_functions[n] = "tolua_is" .. n end return _Enumerate(e, varname) end diff --git a/lib/tolua++/src/bin/lua/function.lua b/lib/tolua++/src/bin/lua/function.lua index 7120fb063..3b6b53c5e 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 isenumtype(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 |