summaryrefslogtreecommitdiffstats
path: root/lib/tolua++/src/bin/lua
diff options
context:
space:
mode:
Diffstat (limited to 'lib/tolua++/src/bin/lua')
-rw-r--r--lib/tolua++/src/bin/lua/basic.lua12
-rw-r--r--lib/tolua++/src/bin/lua/container.lua20
-rw-r--r--lib/tolua++/src/bin/lua/declaration.lua2
-rw-r--r--lib/tolua++/src/bin/lua/enumerate.lua82
-rw-r--r--lib/tolua++/src/bin/lua/function.lua15
5 files changed, 97 insertions, 34 deletions
diff --git a/lib/tolua++/src/bin/lua/basic.lua b/lib/tolua++/src/bin/lua/basic.lua
index f651f1fe6..4bff5276b 100644
--- a/lib/tolua++/src/bin/lua/basic.lua
+++ b/lib/tolua++/src/bin/lua/basic.lua
@@ -23,6 +23,7 @@ _basic = {
['unsigned'] = 'number',
['float'] = 'number',
['double'] = 'number',
+ ['size_t'] = 'number',
['_cstring'] = 'string',
['_userdata'] = 'userdata',
['char*'] = 'string',
@@ -66,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
@@ -145,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 ','')
@@ -382,6 +390,7 @@ end
_push_functions = {}
_is_functions = {}
+_enums = {}
_to_functions = {}
_base_push_functions = {}
@@ -410,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/container.lua b/lib/tolua++/src/bin/lua/container.lua
index 2d11db7df..99488479e 100644
--- a/lib/tolua++/src/bin/lua/container.lua
+++ b/lib/tolua++/src/bin/lua/container.lua
@@ -58,7 +58,7 @@ function classContainer:hasvar ()
while self[i] do
if self[i]:isvariable() then
return 1
- end
+ end
i = i+1
end
return 0
@@ -568,7 +568,7 @@ function classContainer:doparse (s)
-- Enumerate(name,body)
-- return strsub(s,e+1)
-- end
--- end
+-- end
do
local b,e,body,name = strfind(s,"^%s*typedef%s+enum[^{]*(%b{})%s*([%w_][^%s]*)%s*;%s*")
@@ -606,14 +606,14 @@ function classContainer:doparse (s)
-- try function
do
--local b,e,decl,arg,const = strfind(s,"^%s*([~_%w][_@%w%s%*&:<>]*[_%w])%s*(%b())%s*(c?o?n?s?t?)%s*=?%s*0?%s*;%s*")
- local b,e,decl,arg,const,virt = strfind(s,"^%s*([^%(\n]+)%s*(%b())%s*(c?o?n?s?t?)%s*(=?%s*0?)%s*;%s*")
+ local b,e,decl,arg,const,virt = strfind(s,"^%s*([^%(\n]+)%s*(%b())%s*(c?o?n?s?t?)v?e?r?r?i?d?e?%s*o?v?e?r?r?i?d?e?%s*(=?%s*0?)%s*;%s*")
if not b then
-- try function with template
- b,e,decl,arg,const = strfind(s,"^%s*([~_%w][_@%w%s%*&:<>]*[_%w]%b<>)%s*(%b())%s*(c?o?n?s?t?)%s*=?%s*0?%s*;%s*")
+ b,e,decl,arg,const = strfind(s,"^%s*([~_%w][_@%w%s%*&:<>]*[_%w]%b<>)%s*(%b())%s*(c?o?n?s?t?)v?e?r?r?i?d?e?%s*o?v?e?r?r?i?d?e?%s*=?%s*0?%s*;%s*")
end
if not b then
-- try a single letter function name
- b,e,decl,arg,const = strfind(s,"^%s*([_%w])%s*(%b())%s*(c?o?n?s?t?)%s*;%s*")
+ b,e,decl,arg,const = strfind(s,"^%s*([_%w])%s*(%b())%s*(c?o?n?s?t?)v?e?r?r?i?d?e?%s*o?v?e?r?r?i?d?e?%s*;%s*")
end
if not b then
-- try function pointer
@@ -629,6 +629,9 @@ function classContainer:doparse (s)
end
end
_curr_code = strsub(s,b,e)
+ if const == 'o' then
+ const = ''
+ end
Function(decl,arg,const)
return strsub(s,e+1)
end
@@ -636,14 +639,17 @@ function classContainer:doparse (s)
-- try inline function
do
- local b,e,decl,arg,const = strfind(s,"^%s*([^%(\n]+)%s*(%b())%s*(c?o?n?s?t?)[^;{]*%b{}%s*;?%s*")
+ local b,e,decl,arg,const = strfind(s,"^%s*([^%(\n]+)%s*(%b())%s*(c?o?n?s?t?)v?e?r?r?i?d?e?%s*o?v?e?r?r?i?d?e?[^;{]*%b{}%s*;?%s*")
--local b,e,decl,arg,const = strfind(s,"^%s*([~_%w][_@%w%s%*&:<>]*[_%w>])%s*(%b())%s*(c?o?n?s?t?)[^;]*%b{}%s*;?%s*")
if not b then
-- try a single letter function name
- b,e,decl,arg,const = strfind(s,"^%s*([_%w])%s*(%b())%s*(c?o?n?s?t?).-%b{}%s*;?%s*")
+ b,e,decl,arg,const = strfind(s,"^%s*([_%w])%s*(%b())%s*(c?o?n?s?t?)v?e?r?r?i?d?e?%s*o?v?e?r?r?i?d?e?.-%b{}%s*;?%s*")
end
if b then
_curr_code = strsub(s,b,e)
+ if const == 'o' then
+ const = ''
+ end
Function(decl,arg,const)
return strsub(s,e+1)
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 99fe74629..09b22a094 100644
--- a/lib/tolua++/src/bin/lua/enumerate.lua
+++ b/lib/tolua++/src/bin/lua/enumerate.lua
@@ -48,6 +48,25 @@ 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
+ _global_output_enums[self.name] = 1
+ 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);")
+ output("return val >= " .. self.min .. ".0 && val <= " ..self.max .. ".0;")
+ output("}")
+ end
+end
+
-- Internal constructor
function _Enumerate (t,varname)
setmetatable(t,classEnumerate)
@@ -67,40 +86,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
+ _enums[n] = true
Typedef("int "..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..9338e0fbc 100644
--- a/lib/tolua++/src/bin/lua/function.lua
+++ b/lib/tolua++/src/bin/lua/function.lua
@@ -50,11 +50,20 @@ 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()
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
@@ -449,9 +458,8 @@ end
-- Internal constructor
function _Function (t)
setmetatable(t,classFunction)
-
if t.const ~= 'const' and t.const ~= '' then
- error("#invalid 'const' specification")
+ error("#invalid 'const' specification: " .. t.const)
end
append(t)
@@ -480,7 +488,6 @@ end
function Function (d,a,c)
--local t = split(strsub(a,2,-2),',') -- eliminate braces
--local t = split_params(strsub(a,2,-2))
-
if not flags['W'] and string.find(a, "%.%.%.%s*%)") then
warning("Functions with variable arguments (`...') are not supported. Ignoring "..d..a..c)