From 0a505576e5220113dfbcc140b70659f822a17f44 Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 17 Mar 2014 10:28:04 -0700 Subject: Fixed =~ bug --- lib/tolua++/src/bin/lua/enumerate.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/tolua++/src/bin/lua') diff --git a/lib/tolua++/src/bin/lua/enumerate.lua b/lib/tolua++/src/bin/lua/enumerate.lua index 5f0dedfe1..9c534a020 100644 --- a/lib/tolua++/src/bin/lua/enumerate.lua +++ b/lib/tolua++/src/bin/lua/enumerate.lua @@ -52,7 +52,7 @@ _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("{") -- cgit v1.2.3 From e8f7c18ba75be4e62b9b0b7f55c5fe8eae1af1ec Mon Sep 17 00:00:00 2001 From: Tycho Date: Wed, 19 Mar 2014 11:34:33 -0700 Subject: Fixed type error in lua bindings --- lib/tolua++/src/bin/lua/enumerate.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/tolua++/src/bin/lua') diff --git a/lib/tolua++/src/bin/lua/enumerate.lua b/lib/tolua++/src/bin/lua/enumerate.lua index 9c534a020..a00b434aa 100644 --- a/lib/tolua++/src/bin/lua/enumerate.lua +++ b/lib/tolua++/src/bin/lua/enumerate.lua @@ -54,11 +54,11 @@ _global_output_enums = {} 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("lua_Number 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("lua_Number val = tolua_tonumber(L,lo,def);") + output("return val >= " .. self.min .. ".0 && val <= " ..self.max .. ".0;") output("}") end end -- cgit v1.2.3 From 04adca34106a83e7ccd8d3e6107e16d79595ba6d Mon Sep 17 00:00:00 2001 From: Tycho Date: Wed, 19 Mar 2014 12:02:26 -0700 Subject: Fixed tolua emitting isnumber insteand of is --- lib/tolua++/src/bin/lua/basic.lua | 6 +++++- lib/tolua++/src/bin/lua/enumerate.lua | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'lib/tolua++/src/bin/lua') diff --git a/lib/tolua++/src/bin/lua/basic.lua b/lib/tolua++/src/bin/lua/basic.lua index f651f1fe6..d195f6dec 100644 --- a/lib/tolua++/src/bin/lua/basic.lua +++ b/lib/tolua++/src/bin/lua/basic.lua @@ -148,6 +148,9 @@ 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 @@ -382,6 +385,7 @@ end _push_functions = {} _is_functions = {} +_enum_is_functions = {} _to_functions = {} _base_push_functions = {} @@ -410,5 +414,5 @@ function get_to_function(t) end function get_is_function(t) - return _is_functions[t] or search_base(t, _base_is_functions) or "tolua_isusertype" + return _enum_is_functions[t] or _is_functions[t] or search_base(t, _base_is_functions) or "tolua_isusertype" end diff --git a/lib/tolua++/src/bin/lua/enumerate.lua b/lib/tolua++/src/bin/lua/enumerate.lua index a00b434aa..d5d4426cf 100644 --- a/lib/tolua++/src/bin/lua/enumerate.lua +++ b/lib/tolua++/src/bin/lua/enumerate.lua @@ -130,8 +130,8 @@ function Enumerate (n,b,varname) e.min = min e.max = max if n ~= "" then + _enum_is_functions[n] = ("tolua_is" .. n) Typedef("int "..n) - _is_functions[n] = "tolua_is" .. n end return _Enumerate(e, varname) end -- cgit v1.2.3 From 6a3fe7adcc2a3855a574dbfc2bb79c86e7539f26 Mon Sep 17 00:00:00 2001 From: Tycho Date: Wed, 19 Mar 2014 12:38:00 -0700 Subject: Fixed bugs in patched tolua output --- lib/tolua++/src/bin/lua/basic.lua | 15 ++++++++++----- lib/tolua++/src/bin/lua/declaration.lua | 2 ++ lib/tolua++/src/bin/lua/enumerate.lua | 8 ++++++-- lib/tolua++/src/bin/lua/function.lua | 10 ++++++++++ 4 files changed, 28 insertions(+), 7 deletions(-) (limited to 'lib/tolua++/src/bin/lua') 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 -- cgit v1.2.3 From a69a1ef0325c5e472f1dd736f3a14a260d747ad9 Mon Sep 17 00:00:00 2001 From: Tycho Date: Thu, 20 Mar 2014 13:23:15 -0700 Subject: Fixed enum checking functions not being called in generated code --- lib/tolua++/src/bin/lua/basic.lua | 4 +++- lib/tolua++/src/bin/lua/declaration.lua | 4 ++-- lib/tolua++/src/bin/lua/enumerate.lua | 6 +++--- lib/tolua++/src/bin/lua/function.lua | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) (limited to 'lib/tolua++/src/bin/lua') diff --git a/lib/tolua++/src/bin/lua/basic.lua b/lib/tolua++/src/bin/lua/basic.lua index b5788f2be..425cb6861 100644 --- a/lib/tolua++/src/bin/lua/basic.lua +++ b/lib/tolua++/src/bin/lua/basic.lua @@ -66,6 +66,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,7 +148,7 @@ function typevar(type) end -- is enum -function isenum (type) +function isenumtype (type) return _enums[type] end diff --git a/lib/tolua++/src/bin/lua/declaration.lua b/lib/tolua++/src/bin/lua/declaration.lua index 5a2adfed9..26ceeba22 100644 --- a/lib/tolua++/src/bin/lua/declaration.lua +++ b/lib/tolua++/src/bin/lua/declaration.lua @@ -227,10 +227,10 @@ 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)' - 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 ef3a9574c..09b22a094 100644 --- a/lib/tolua++/src/bin/lua/enumerate.lua +++ b/lib/tolua++/src/bin/lua/enumerate.lua @@ -49,7 +49,7 @@ function classEnumerate: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);") + output("int tolua_is" .. string.gsub(type,"::","_") .. " (lua_State* L, int lo, int def, tolua_Error* err);") end _global_output_enums = {} @@ -58,7 +58,7 @@ _global_output_enums = {} function classEnumerate:supcode () if _global_output_enums[self.name] == nil then _global_output_enums[self.name] = 1 - output("int tolua_is" .. string.gsub(self.name,"::","_") .. " (lua_State* L, int lo, const char * type, 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("lua_Number val = tolua_tonumber(L,lo,def);") @@ -134,7 +134,7 @@ function Enumerate (n,b,varname) e.min = min e.max = max if n ~= "" then - _enums[n] = 1 + _enums[n] = true 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 ad1ab4225..3b6b53c5e 100644 --- a/lib/tolua++/src/bin/lua/function.lua +++ b/lib/tolua++/src/bin/lua/function.lua @@ -58,7 +58,7 @@ function classFunction:supcode (local_constructor) if self.args[1].type ~= 'void' then local i=1 while self.args[i] do - if isenum(self.args[i].type) then + if isenumtype(self.args[i].type) then emitenumprototype(self.args[i].type) end i = i+1 -- cgit v1.2.3