Changeset 3127 for code/branches/pch
- Timestamp:
- Jun 9, 2009, 4:29:42 PM (15 years ago)
- Location:
- code/branches/pch/src/tolua
- Files:
-
- 1 added
- 27 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pch/src/tolua/CMakeLists.txt
r3116 r3127 54 54 ORXONOX_EXTERNAL 55 55 VERSION 56 1.0.9 256 1.0.93 57 57 LINK_LIBRARIES 58 58 ${LUA_LIBRARIES} … … 88 88 ${CMAKE_CURRENT_SOURCE_DIR}/lua/class.lua 89 89 ${CMAKE_CURRENT_SOURCE_DIR}/lua/clean.lua 90 ${CMAKE_CURRENT_SOURCE_DIR}/lua/template_class.lua 90 91 ${CMAKE_CURRENT_SOURCE_DIR}/lua/doit.lua 91 92 -
code/branches/pch/src/tolua/README
r2710 r3127 14 14 15 15 * Availability 16 tolua is freely available; you can redistribute it and/or modify it.17 The software provided hereunder is on an "as is" basis, and18 the author has no obligation to provide maintenance, support,19 updates, enhancements, or modifications.20 16 21 tolua can be downloaded from the sites below: 17 tolua++ is freely available for both academic and commercial purposes. 18 See COPYRIGHT for details. 19 20 tolua++ can be downloaded from the sites below: 22 21 http://www.codenix.com/~tolua/ 23 http://www.codenix.com/~tolua/tolua++-1.0.tar.bz224 22 25 23 * Installation -
code/branches/pch/src/tolua/VERSION
r2710 r3127 1 Tolua++ v1.0.9 2with changes:1 Tolua++ v1.0.93 with changes: 2 2 3 3 - Exception handling by CEGUI team -
code/branches/pch/src/tolua/all-5.0.lua
r3068 r3127 18 18 dofile(path.."lua/class.lua") 19 19 dofile(path.."lua/clean.lua") 20 dofile(path.."lua/template_class.lua") 20 21 --dofile(path.."lua/custom.lua") 21 22 dofile(path.."lua/doit.lua") -
code/branches/pch/src/tolua/all-5.1.lua
r3068 r3127 19 19 dofile(path.."lua/class.lua") 20 20 dofile(path.."lua/clean.lua") 21 dofile(path.."lua/template_class.lua") 21 22 --dofile(path.."lua/custom.lua") 22 23 dofile(path.."lua/doit.lua") -
code/branches/pch/src/tolua/changes_orxonox.diff
r2710 r3127 1 diff -ruN tolua/tolua++.h tolua2/tolua++.h 2 --- tolua/tolua++.h Wed Jan 28 21:51:38 2009 3 +++ tolua2/tolua++.h Sat Jan 10 14:48:44 2009 1 --- tolua++.h Tue Jun 9 16:27:17 2009 2 +++ tolua++.h Tue Jun 9 14:50:04 2009 4 3 @@ -16,9 +16,34 @@ 5 4 #ifndef TOLUA_H … … 37 36 #define TOLUA_VERSION "tolua++-1.0.92" 38 37 39 diff -ruN tolua/tolua.c tolua2/tolua.c 40 --- tolua/tolua.c Wed Jan 28 21:51:00 2009 41 +++ tolua2/tolua.c Sat Jan 10 14:48:45 2009 38 --- tolua.c Tue Jun 9 16:27:12 2009 39 +++ tolua.c Tue Jun 9 14:50:04 2009 42 40 @@ -4,6 +4,8 @@ 43 41 ** TeCGraf/PUC-Rio … … 58 56 " -P : parse and print structure information (for debug).\n" 59 57 " -S : disable support for c++ strings.\n" 60 @@ -6 4,12 +68,12 @@58 @@ -65,12 +69,12 @@ 61 59 } 62 60 … … 77 75 78 76 static void error (char* o) 79 @@ -8 1,6 +85,9 @@77 @@ -82,6 +86,9 @@ 80 78 81 79 int main (int argc, char* argv[]) … … 87 85 lua_State* L = luaL_newstate(); 88 86 luaL_openlibs(L); 89 @@ -9 7,6 +104,7 @@87 @@ -98,6 +105,7 @@ 90 88 lua_pushstring(L,TOLUA_VERSION); lua_setglobal(L,"TOLUA_VERSION"); 91 89 lua_pushstring(L,LUA_VERSION); lua_setglobal(L,"TOLUA_LUA_VERSION"); … … 95 93 { 96 94 help(); 97 @@ -12 4,6 +132,14 @@95 @@ -125,6 +133,14 @@ 98 96 case 'o': setfield(L,t,"o",argv[++i]); break; 99 97 case 'n': setfield(L,t,"n",argv[++i]); break; … … 110 108 case '1': setfield(L,t,"1",""); break; 111 109 case 'L': setfield(L,t,"L",argv[++i]); break; 112 @@ -14 3,25 +159,53 @@110 @@ -145,25 +161,53 @@ 113 111 } 114 112 lua_pop(L,1); -
code/branches/pch/src/tolua/lua/array.lua
r2710 r3127 102 102 -- return value 103 103 local t,ct = isbasic(self.type) 104 local push_func = get_push_function(t) 104 105 if t then 105 106 output(' tolua_push'..t..'(tolua_S,(',ct,')'..self:getvalue(class,static)..');') … … 107 108 t = self.type 108 109 if self.ptr == '&' or self.ptr == '' then 109 output(' tolua_pushusertype(tolua_S,(void*)&'..self:getvalue(class,static)..',"',t,'");')110 else 111 output(' tolua_pushusertype(tolua_S,(void*)'..self:getvalue(class,static)..',"',t,'");')110 output(' ',push_func,'(tolua_S,(void*)&'..self:getvalue(class,static)..',"',t,'");') 111 else 112 output(' ',push_func,'(tolua_S,(void*)'..self:getvalue(class,static)..',"',t,'");') 112 113 end 113 114 end … … 193 194 output('tolua_to'..t,'(tolua_S,3,',def,'));') 194 195 else 195 output('tolua_tousertype(tolua_S,3,',def,'));') 196 local to_func = get_to_function(self.type) 197 output(to_func,'(tolua_S,3,',def,'));') 196 198 end 197 199 output(' return 0;') … … 203 205 204 206 function classArray:register (pre) 207 if not self:check_public_access() then 208 return 209 end 210 205 211 pre = pre or '' 206 212 if self.csetname then -
code/branches/pch/src/tolua/lua/basic.lua
r2710 r3127 112 112 113 113 function warning (msg) 114 if flags.q then 115 return 116 end 114 117 local out = _OUTPUT 115 118 _OUTPUT = _STDERR … … 333 336 end 334 337 338 -- called before starting output 339 function pre_output_hook(package) 340 341 end 335 342 336 343 -- called after writing all the output. … … 354 361 end 355 362 356 363 -- called from classFunction:supcode, before the call to the function is output 364 function pre_call_hook(f) 365 366 end 367 368 -- called from classFunction:supcode, after the call to the function is output 369 function post_call_hook(f) 370 371 end 372 373 -- called before the register code is output 374 function pre_register_hook(package) 375 376 end 377 378 -- called to output an error message 379 function output_error_hook(...) 380 return string.format(...) 381 end 382 383 -- custom pushers 384 385 _push_functions = {} 386 _is_functions = {} 387 _to_functions = {} 388 389 _base_push_functions = {} 390 _base_is_functions = {} 391 _base_to_functions = {} 392 393 local function search_base(t, funcs) 394 local class = _global_classes[t] 395 396 while class do 397 if funcs[class.type] then 398 return funcs[class.type] 399 end 400 class = _global_classes[class.btype] 401 end 402 return nil 403 end 404 405 function get_push_function(t) 406 return _push_functions[t] or search_base(t, _base_push_functions) or "tolua_pushusertype" 407 end 408 409 function get_to_function(t) 410 return _to_functions[t] or search_base(t, _base_to_functions) or "tolua_tousertype" 411 end 412 413 function get_is_function(t) 414 return _is_functions[t] or search_base(t, _base_is_functions) or "tolua_isusertype" 415 end 416 -
code/branches/pch/src/tolua/lua/class.lua
r2710 r3127 64 64 -- return collection requirement 65 65 function classClass:requirecollection (t) 66 if self.flags.protected_destructor then66 if self.flags.protected_destructor or (not self:check_public_access()) then 67 67 return false 68 68 end … … 148 148 -- check for template 149 149 b = string.gsub(b, "^{%s*TEMPLATE_BIND", "{\nTOLUA_TEMPLATE_BIND") 150 local t,_,T,I = string.find(b, "^{%s*TOLUA_TEMPLATE_BIND%s*%(+%s*\"?([^\",]*)\"?%s*,%s*([^%)]*)%s*%)+")150 local t,_,T,I = string.find(b, '^{%s*TOLUA_TEMPLATE_BIND%s*%(+%s*\"?([^\",]*)\"?%s*,%s*([^%)]*)%s*%)+') 151 151 if t then 152 152 … … 159 159 local bs = string.gsub(b, "^{%s*TOLUA_TEMPLATE_BIND[^\n]*\n", "{\n") 160 160 161 -- replace 162 for i =1 , types.n do 163 164 local Tl = split(T, " ") 165 local Il = split_c_tokens(types[i], " ") 166 local bI = bs 167 local pI = {} 168 for j = 1,Tl.n do 169 Tl[j] = findtype(Tl[j]) or Tl[j] 170 bI = string.gsub(bI, "([^_%w])"..Tl[j].."([^_%w])", "%1"..Il[j].."%2") 171 if p then 172 for i=1,table.getn(p) do 173 pI[i] = string.gsub(p[i], "([^_%w]?)"..Tl[j].."([^_%w]?)", "%1"..Il[j].."%2") 174 end 175 end 176 end 177 --local append = "<"..string.gsub(types[i], "%s+", ",")..">" 178 local append = "<"..concat(Il, 1, table.getn(Il), ",")..">" 179 append = string.gsub(append, "%s*,%s*", ",") 180 append = string.gsub(append, ">>", "> >") 181 for i=1,table.getn(pI) do 182 --pI[i] = string.gsub(pI[i], ">>", "> >") 183 pI[i] = resolve_template_types(pI[i]) 184 end 185 bI = string.gsub(bI, ">>", "> >") 186 Class(n..append, pI, bI) 187 end 161 local Tl = split(T, " ") 162 local tc = TemplateClass(n, p, bs, Tl) 163 164 tc:throw(types, true) 165 --for i=1,types.n do 166 -- tc:throw(split_c_tokens(types[i], " "), true) 167 --end 188 168 return 189 169 end -
code/branches/pch/src/tolua/lua/code.lua
r2710 r3127 47 47 end 48 48 49 -- pad to 16 bytes 50 local npad = 16 - (#s % 16) 51 local spad = "" 52 for i=1,npad do 53 spad = spad .. "-" 54 end 55 s = s..spad 56 49 57 -- convert to C 50 58 output('\n'..pre..'{ /* begin embedded lua code */\n') 51 59 output(pre..' int top = lua_gettop(tolua_S);') 52 output(pre..' static unsigned char B[] = {\n ')60 output(pre..' static const unsigned char B[] = {\n ') 53 61 local t={n=0} 54 62 local b = gsub(s, '(.)', -
code/branches/pch/src/tolua/lua/compat-5.1.lua
r2710 r3127 26 26 27 27 local f = load(getfile, path) 28 if not f then 29 error("error loading file "..path) 30 end 28 31 return f() 29 32 end -
code/branches/pch/src/tolua/lua/container.lua
r2710 r3127 615 615 b,e,decl,arg,const = strfind(s,"^%s*([_%w])%s*(%b())%s*(c?o?n?s?t?)%s*;%s*") 616 616 end 617 if not b then 618 -- try function pointer 619 b,e,decl,arg,const = strfind(s,"^%s*([^%(;\n]+%b())%s*(%b())%s*;%s*") 620 if b then 621 decl = string.gsub(decl, "%(%s*%*([^%)]*)%s*%)", " %1 ") 622 end 623 end 617 624 if b then 618 625 if virt and string.find(virt, "[=0]") then … … 647 654 base = '' body = '' 648 655 b,e,name = strfind(s,"^%s*class%s*([_%w][_%w@]*)%s*;") -- dummy class 656 local dummy = false 649 657 if not b then 650 658 b,e,name = strfind(s,"^%s*struct%s*([_%w][_%w@]*)%s*;") -- dummy struct 651 659 if not b then 652 b,e,name,base,body = strfind(s,"^%s*class%s*([_%w][_%w@]*)%s*( .-)%s*(%b{})%s*;%s*")660 b,e,name,base,body = strfind(s,"^%s*class%s*([_%w][_%w@]*)%s*([^{]-)%s*(%b{})%s*") 653 661 if not b then 654 b,e,name,base,body = strfind(s,"^%s*struct%s *([_%w][_%w@]*)%s*(.-)%s*(%b{})%s*;%s*")662 b,e,name,base,body = strfind(s,"^%s*struct%s+([_%w][_%w@]*)%s*([^{]-)%s*(%b{})%s*") 655 663 if not b then 656 b,e,name,base,body = strfind(s,"^%s*union%s*([_%w][_%w@]*)%s*( .-)%s*(%b{})%s*;%s*")664 b,e,name,base,body = strfind(s,"^%s*union%s*([_%w][_%w@]*)%s*([^{]-)%s*(%b{})%s*") 657 665 if not b then 658 666 base = '' 659 b,e,body,name = strfind(s,"^%s*typedef%s%s*struct%s%s*[_%w]*%s*(%b{})%s*([_%w][_%w@]*)%s*; %s*")667 b,e,body,name = strfind(s,"^%s*typedef%s%s*struct%s%s*[_%w]*%s*(%b{})%s*([_%w][_%w@]*)%s*;") 660 668 end 661 669 end 662 670 end 663 e nd664 e nd671 else dummy = 1 end 672 else dummy = 1 end 665 673 if b then 666 674 if base ~= '' then … … 675 683 _curr_code = strsub(s,b,e) 676 684 Class(name,base,body) 685 if not dummy then 686 varb,vare,varname = string.find(s, "^%s*([_%w]+)%s*;", e+1) 687 if varb then 688 Variable(name.." "..varname) 689 e = vare 690 end 691 end 677 692 return strsub(s,e+1) 678 693 end … … 723 738 -- try array 724 739 do 725 local b,e,decl = strfind(s,"^%s*([_%w][][_@%s%w%d%*&:]*[]_%w%d])%s*;%s*")740 local b,e,decl = strfind(s,"^%s*([_%w][][_@%s%w%d%*&:<>]*[]_%w%d])%s*;%s*") 726 741 if b then 727 742 _curr_code = strsub(s,b,e) … … 743 758 function classContainer:parse (s) 744 759 745 self.curr_member_access = nil760 --self.curr_member_access = nil 746 761 747 762 while s ~= '' do -
code/branches/pch/src/tolua/lua/declaration.lua
r2710 r3127 140 140 for i=1, table.getn(m) do 141 141 m[i] = string.gsub(m[i],"%s*([%*&])", "%1") 142 m[i] = findtype(m[i]) or m[i] 143 m[i] = resolve_template_types(m[i]) 142 if not isbasic(m[i]) then 143 if not isenum(m[i]) then _, m[i] = applytypedef("", m[i]) end 144 m[i] = findtype(m[i]) or m[i] 145 m[i] = resolve_template_types(m[i]) 146 end 144 147 end 145 148 146 149 local b,i 147 150 type,b,i = break_template(type) 148 local template_part = "<"..string.gsub(concat(m, 1, m.n), " ", ",")..">" 151 --print("concat is ",concat(m, 1, m.n)) 152 local template_part = "<"..concat(m, 1, m.n, ",")..">" 149 153 type = rebuild_template(type, b, template_part) 150 154 type = string.gsub(type, ">>", "> >") … … 187 191 -- check if array of values are returned to Lua 188 192 function classDeclaration:requirecollection (t) 189 if self.mod ~= 'const' and193 if self.mod ~= 'const' and 190 194 self.dim and self.dim ~= '' and 191 195 not isbasic(self.type) and 192 self.ptr == '' then196 self.ptr == '' and self:check_public_access() then 193 197 local type = gsub(self.type,"%s*const%s+","") 194 198 t[type] = "tolua_collect_" .. clean_template(type) … … 222 226 -- return 'tolua_isstringarray(tolua_S,'..narg..','..def..',&tolua_err)' 223 227 --else 224 return ' tolua_istable(tolua_S,'..narg..',0,&tolua_err)'228 return '!tolua_istable(tolua_S,'..narg..',0,&tolua_err)' 225 229 --end 226 230 elseif t then 227 return 'tolua_is'..t..'(tolua_S,'..narg..','..def..',&tolua_err)' 228 else 229 return 'tolua_isusertype(tolua_S,'..narg..',"'..self.type..'",'..def..',&tolua_err)' 230 end 231 return '!tolua_is'..t..'(tolua_S,'..narg..','..def..',&tolua_err)' 232 else 233 local is_func = get_is_function(self.type) 234 if self.ptr == '&' or self.ptr == '' then 235 return '(tolua_isvaluenil(tolua_S,'..narg..',&tolua_err) || !'..is_func..'(tolua_S,'..narg..',"'..self.type..'",'..def..',&tolua_err))' 236 else 237 return '!'..is_func..'(tolua_S,'..narg..',"'..self.type..'",'..def..',&tolua_err)' 238 end 239 end 231 240 end 232 241 … … 237 246 local mod 238 247 local type = self.type 248 local nctype = gsub(self.type,'const%s+','') 239 249 if self.dim ~= '' then 240 250 type = gsub(self.type,'const%s+','') -- eliminates const modifier for arrays … … 251 261 else 252 262 if cplusplus then 253 line = concatparam(line,' = new',type,ptr,'['..self.dim..'];')263 line = concatparam(line,' = Mtolua_new_dim(',type,ptr,', '..self.dim..');') 254 264 else 255 265 line = concatparam(line,' = (',type,ptr,'*)', … … 273 283 end 274 284 line = concatparam(line,') ') 275 if isenum( type) then285 if isenum(nctype) then 276 286 line = concatparam(line,'(int) ') 277 287 end … … 286 296 line = concatparam(line,'tolua_to'..t,'(tolua_S,',narg,',',def,'));') 287 297 else 288 line = concatparam(line,'tolua_tousertype(tolua_S,',narg,',',def,'));') 298 local to_func = get_to_function(type) 299 line = concatparam(line,to_func..'(tolua_S,',narg,',',def,'));') 289 300 end 290 301 end … … 361 372 output(' {') 362 373 output('#ifdef __cplusplus\n') 363 output(' void* tolua_obj = new',type,'(',self.name,'[i]);')374 output(' void* tolua_obj = Mtolua_new((',type,')(',self.name,'[i]));') 364 375 output(' tolua_pushfieldusertype_and_takeownership(tolua_S,',narg,',i+1,tolua_obj,"',type,'");') 365 376 output('#else\n') … … 380 391 if self.dim ~= '' and tonumber(self.dim)==nil then 381 392 output('#ifdef __cplusplus\n') 382 output(' delete []',self.name,';')393 output(' Mtolua_delete_dim(',self.name,');') 383 394 output('#else\n') 384 395 output(' free(',self.name,');') … … 405 416 output(' tolua_push'..t..'(tolua_S,(',ct,')'..self.name..');') 406 417 else 407 output(' tolua_pushusertype(tolua_S,(void*)'..self.name..',"',self.type,'");') 418 local push_func = get_push_function(self.type) 419 output(' ',push_func,'(tolua_S,(void*)'..self.name..',"',self.type,'");') 408 420 end 409 421 return 1 -
code/branches/pch/src/tolua/lua/doit.lua
r2710 r3127 16 16 for k,v in ipairs(_extra_parameters or {}) do 17 17 18 local b,e,name,value = string.find(v, "^([^=] )=(.*)$")18 local b,e,name,value = string.find(v, "^([^=]*)=(.*)$") 19 19 if b then 20 20 _extra_parameters[name] = value … … 94 94 p:print() 95 95 else 96 push(p) 97 pre_output_hook(p) 98 pop() 96 99 p:preamble() 97 100 p:supcode() 101 push(p) 102 pre_register_hook(p) 103 pop() 98 104 p:register() 99 105 push(p) -
code/branches/pch/src/tolua/lua/enumerate.lua
r2710 r3127 22 22 -- register enumeration 23 23 function classEnumerate:register (pre) 24 if not self:check_public_access() then 25 return 26 end 24 27 pre = pre or '' 25 28 local nspace = getnamespace(classContainer.curr) 26 29 local i=1 27 30 while self[i] do 28 output(pre..'tolua_constant(tolua_S,"'..self.lnames[i]..'",'..nspace..self[i]..');') 31 if self.lnames[i] and self.lnames[i] ~= "" then 32 output(pre..'tolua_constant(tolua_S,"'..self.lnames[i]..'",'..nspace..self[i]..');') 33 end 29 34 i = i+1 30 35 end … … 56 61 Variable("tolua_readonly int "..varname) 57 62 end 63 end 64 local parent = classContainer.curr 65 if parent then 66 t.access = parent.curr_member_access 67 t.global_access = t:check_public_access() 58 68 end 59 69 return t -
code/branches/pch/src/tolua/lua/feature.lua
r2710 r3127 48 48 local n = split(self.name,'@') 49 49 self.name = n[1] 50 self.name = string.gsub(self.name, ":%d*$", "") 50 51 if not n[2] then 51 52 n[2] = applyrenaming(n[1]) 52 53 end 53 54 self.lname = n[2] or gsub(n[1],"%[.-%]","") 55 self.lname = string.gsub(self.lname, ":%d*$", "") 54 56 self.original_name = self.name 55 57 self.lname = clean_template(self.lname) … … 62 64 if parent then 63 65 self.access = parent.curr_member_access 66 self.global_access = self:check_public_access() 64 67 else 65 68 end … … 67 70 68 71 function classFeature:check_public_access() 72 73 if type(self.global_access) == "boolean" then 74 return self.global_access 75 end 69 76 70 77 if self.access and self.access ~= 0 then … … 122 129 end 123 130 124 n = string.gsub(n..'_'.. (self.lname or self.name), "[<>:, \.%*&]", "_") 131 local fname = self.lname 132 if not fname or fname == '' then 133 fname = self.name 134 end 135 n = string.gsub(n..'_'.. (fname), "[<>:, \.%*&]", "_") 125 136 126 137 return n -
code/branches/pch/src/tolua/lua/function.lua
r2710 r3127 209 209 if class then narg=2 else narg=1 end 210 210 if class then 211 local func = 'tolua_isusertype'211 local func = get_is_function(self.parent.type) 212 212 local type = self.parent.type 213 213 if self.name=='new' or static~=nil then … … 226 226 local btype = isbasic(self.args[i].type) 227 227 if btype ~= 'value' and btype ~= 'state' then 228 output(' !'..self.args[i]:outchecktype(narg)..' ||\n')228 output(' '..self.args[i]:outchecktype(narg)..' ||\n') 229 229 end 230 230 if btype ~= 'state' then … … 250 250 output(' ',self.const,self.parent.type,'*','self = ') 251 251 output('(',self.const,self.parent.type,'*) ') 252 output('tolua_tousertype(tolua_S,1,0);') 252 local to_func = get_to_function(self.parent.type) 253 output(to_func,'(tolua_S,1,0);') 253 254 elseif static then 254 255 _,_,self.mod = strfind(self.mod,'^%s*static%s%s*(.*)') … … 269 270 if class and self.name~='new' and static==nil then 270 271 output('#ifndef TOLUA_RELEASE\n') 271 output(' if (!self) tolua_error(tolua_S," invalid \'self\' in function \''..self.name..'\'",NULL);');272 output(' if (!self) tolua_error(tolua_S,"'..output_error_hook("invalid \'self\' in function \'%s\'", self.name)..'", NULL);'); 272 273 output('#endif\n') 273 274 end … … 312 313 -------------------------------------------------- 313 314 315 pre_call_hook(self) 316 314 317 local out = string.find(self.mod, "tolua_outside") 315 318 … … 323 326 -- call function 324 327 if class and self.name=='delete' then 325 output(' delete self;')328 output(' Mtolua_delete(self);') 326 329 elseif class and self.name == 'operator&[]' then 327 330 if flags['1'] then -- for compatibility with tolua5 ? … … 352 355 end 353 356 if class and self.name=='new' then 354 output(' new',self.type,'(')357 output('Mtolua_new((',self.type,')(') 355 358 elseif class and static then 356 359 if out then … … 364 367 else 365 368 if self.cast_operator then 366 output('static_cast<',self.mod,self.type,self.ptr,'>(*self') 369 --output('static_cast<',self.mod,self.type,self.ptr,' >(*self') 370 output('self->operator ',self.mod,self.type,'(') 367 371 else 368 372 output('self->'..self.name,'(') … … 392 396 output('-1);') 393 397 else 394 output(');') 398 if class and self.name=='new' then 399 output('));') -- close Mtolua_new( 400 else 401 output(');') 402 end 395 403 end 396 404 … … 399 407 nret = nret + 1 400 408 local t,ct = isbasic(self.type) 401 if t then409 if t and self.name ~= "new" then 402 410 if self.cast_operator and _basic_raw_push[t] then 403 411 output(' ',_basic_raw_push[t],'(tolua_S,(',ct,')tolua_ret);') … … 408 416 t = self.type 409 417 new_t = string.gsub(t, "const%s+", "") 418 local owned = false 419 if string.find(self.mod, "tolua_owned") then 420 owned = true 421 end 422 local push_func = get_push_function(t) 410 423 if self.ptr == '' then 411 424 output(' {') 412 425 output('#ifdef __cplusplus\n') 413 output(' void* tolua_obj = new',new_t,'(tolua_ret);') 414 output(' tolua_pushusertype_and_takeownership(tolua_S,tolua_obj,"',t,'");') 426 output(' void* tolua_obj = Mtolua_new((',new_t,')(tolua_ret));') 427 output(' ',push_func,'(tolua_S,tolua_obj,"',t,'");') 428 output(' tolua_register_gc(tolua_S,lua_gettop(tolua_S));') 415 429 output('#else\n') 416 430 output(' void* tolua_obj = tolua_copy(tolua_S,(void*)&tolua_ret,sizeof(',t,'));') 417 output(' tolua_pushusertype_and_takeownership(tolua_S,tolua_obj,"',t,'");') 431 output(' ',push_func,'(tolua_S,tolua_obj,"',t,'");') 432 output(' tolua_register_gc(tolua_S,lua_gettop(tolua_S));') 418 433 output('#endif\n') 419 434 output(' }') 420 435 elseif self.ptr == '&' then 421 output(' tolua_pushusertype(tolua_S,(void*)&tolua_ret,"',t,'");')436 output(' ',push_func,'(tolua_S,(void*)&tolua_ret,"',t,'");') 422 437 else 423 if local_constructor then 424 output(' tolua_pushusertype_and_takeownership(tolua_S,(void *)tolua_ret,"',t,'");') 425 else 426 output(' tolua_pushusertype(tolua_S,(void*)tolua_ret,"',t,'");') 438 output(' ',push_func,'(tolua_S,(void*)tolua_ret,"',t,'");') 439 if owned or local_constructor then 440 output(' tolua_register_gc(tolua_S,lua_gettop(tolua_S));') 427 441 end 428 442 end … … 466 480 end 467 481 482 post_call_hook(self) 483 468 484 output(' }') 469 485 output(' return '..nret..';') … … 474 490 output('#ifndef TOLUA_RELEASE\n') 475 491 output('tolua_lerror:\n') 476 output(' tolua_error(tolua_S," #ferror in function \''..self.lname..'\'.",&tolua_err);')492 output(' tolua_error(tolua_S,"'..output_error_hook("#ferror in function \'%s\'.", self.lname)..'",&tolua_err);') 477 493 output(' return 0;') 478 494 output('#endif\n') … … 574 590 if string.find(par, "%*") then -- it's a pointer with a default value 575 591 576 if string.find(par, '=%s*new') then -- it's a pointer with an instance as default parameter.. is that valid?592 if string.find(par, '=%s*new') or string.find(par, "%(") then -- it's a pointer with an instance as default parameter.. is that valid? 577 593 return true 578 594 end … … 661 677 --ns = strip_defaults(ns) 662 678 663 Function(d, ns, c)679 local f = Function(d, ns, c) 664 680 for i=1,last do 665 681 t[i] = string.gsub(t[i], "=.*$", "") -
code/branches/pch/src/tolua/lua/operator.lua
r2710 r3127 75 75 output(' if (\n') 76 76 -- check self 77 output(' !'..'tolua_isusertype(tolua_S,1,"'..self.parent.type..'",0,&tolua_err) ||\n') 77 local is_func = get_is_function(self.parent.type) 78 output(' !'..is_func..'(tolua_S,1,"'..self.parent.type..'",0,&tolua_err) ||\n') 78 79 output(' !tolua_isnoobj(tolua_S,2,&tolua_err)\n )') 79 80 output(' goto tolua_lerror;') … … 86 87 output(' ',self.const,self.parent.type,'*','self = ') 87 88 output('(',self.const,self.parent.type,'*) ') 88 output('tolua_tousertype(tolua_S,1,0);') 89 local to_func = get_to_func(self.parent.type) 90 output(to_func,'(tolua_S,1,0);') 89 91 90 92 -- check self 91 93 output('#ifndef TOLUA_RELEASE\n') 92 output(' if (!self) tolua_error(tolua_S," invalid \'self\' in function \''..self.name..'\'",NULL);');94 output(' if (!self) tolua_error(tolua_S,"'..output_error_hook("invalid \'self\' in function \'%s\'", self.name)..'",NULL);'); 93 95 output('#endif\n') 94 96 … … 103 105 else 104 106 t = self.type 107 local push_func = get_push_function(t) 105 108 new_t = string.gsub(t, "const%s+", "") 106 109 if self.ptr == '' then 107 110 output(' {') 108 111 output('#ifdef __cplusplus\n') 109 output(' void* tolua_obj = new',new_t,'(tolua_ret);') 110 output(' tolua_pushusertype_and_takeownership(tolua_S,tolua_obj,"',t,'");') 112 output(' void* tolua_obj = Mtolua_new((',new_t,')(tolua_ret));') 113 output(' ',push_func,'(tolua_S,tolua_obj,"',t,'");') 114 output(' tolua_register_gc(tolua_S,lua_gettop(tolua_S));') 111 115 output('#else\n') 112 116 output(' void* tolua_obj = tolua_copy(tolua_S,(void*)&tolua_ret,sizeof(',t,'));') 113 output(' tolua_pushusertype_and_takeownership(tolua_S,tolua_obj,"',t,'");') 117 output(' ',push_func,'(tolua_S,tolua_obj,"',t,'");') 118 output(' tolua_register_gc(tolua_S,lua_gettop(tolua_S));') 114 119 output('#endif\n') 115 120 output(' }') 116 121 elseif self.ptr == '&' then 117 output(' tolua_pushusertype(tolua_S,(void*)&tolua_ret,"',t,'");')122 output(' ',push_func,'(tolua_S,(void*)&tolua_ret,"',t,'");') 118 123 else 119 124 if local_constructor then 120 output(' tolua_pushusertype_and_takeownership(tolua_S,(void *)tolua_ret,"',t,'");') 125 output(' ',push_func,'(tolua_S,(void *)tolua_ret,"',t,'");') 126 output(' tolua_register_gc(tolua_S,lua_gettop(tolua_S));') 121 127 else 122 output(' tolua_pushusertype(tolua_S,(void*)tolua_ret,"',t,'");')128 output(' ',push_func,'(tolua_S,(void*)tolua_ret,"',t,'");') 123 129 end 124 130 end … … 130 136 output('#ifndef TOLUA_RELEASE\n') 131 137 output('tolua_lerror:\n') 132 output(' tolua_error(tolua_S," #ferror in function \''..self.lname..'\'.",&tolua_err);')138 output(' tolua_error(tolua_S,"'..output_error_hook("#ferror in function \'%s\'.", self.lname)..'",&tolua_err);') 133 139 output(' return 0;') 134 140 output('#endif\n') -
code/branches/pch/src/tolua/lua/package.lua
r2710 r3127 42 42 return "\n#["..getn(L).."]#" 43 43 end 44 ) 45 -- avoid preprocessing embedded C code 44 ) -- avoid preprocessing embedded C code 46 45 local C = {} 47 46 self.code = gsub(self.code,"\n%s*%$%<","\3") -- deal with embedded C code … … 51 50 return "\n#<"..getn(C)..">#" 52 51 end 53 ) 54 -- avoid preprocessing embedded C code 52 ) -- avoid preprocessing embedded C code 55 53 self.code = gsub(self.code,"\n%s*%$%{","\5") -- deal with embedded C code 56 54 self.code = gsub(self.code,"\n%s*%$%}","\6") … … 60 58 end 61 59 ) 62 63 60 --self.code = gsub(self.code,"\n%s*#[^d][^\n]*\n", "\n\n") -- eliminate preprocessor directives that don't start with 'd' 64 61 self.code = gsub(self.code,"\n[ \t]*#[ \t]*[^d%<%[]", "\n//") -- eliminate preprocessor directives that don't start with 'd' … … 71 68 end 72 69 ) 73 74 70 -- perform global substitution 75 71 … … 94 90 return L[tonumber(n)] 95 91 end 96 ) 97 -- restore embedded C code 92 ) -- restore embedded C code 98 93 self.code = gsub(self.code,"%#%<(%d+)%>%#", function (n) 99 94 return C[tonumber(n)] 100 95 end 101 ) 102 -- restore verbatim lines 96 ) -- restore verbatim lines 103 97 self.code = gsub(self.code,"%#(%d+)%#", function (n) 104 98 return V[tonumber(n)] 105 99 end 106 100 ) 107 108 101 self.code = string.gsub(self.code, "\n%s*%$([^\n]+)", function (l) 109 102 Verbatim(l.."\n") 110 103 return "\n" 111 104 end 112 ) 113 end 114 105 )end 115 106 -- translate verbatim 116 107 function classPackage:preamble () … … 146 137 output('{') 147 138 output(' '..i..'* self = ('..i..'*) tolua_tousertype(tolua_S,1,0);') 148 output(' delete self;')139 output(' Mtolua_delete(self);') 149 140 output(' return 0;') 150 141 output('}') … … 157 148 output('static void tolua_reg_types (lua_State* tolua_S)') 158 149 output('{') 159 foreach(_usertype,function(n,v) output(' tolua_usertype(tolua_S,"',v,'");') end) 150 160 151 if flags.t then 161 152 output("#ifndef Mtolua_typeid\n#define Mtolua_typeid(L,TI,T)\n#endif\n") 162 foreach(_usertype,function(n,v) output(' Mtolua_typeid(tolua_S,typeid(',v,'), "',v,'");') end) 163 end 153 end 154 foreach(_usertype,function(n,v) 155 if (not _global_classes[v]) or _global_classes[v]:check_public_access() then 156 output(' tolua_usertype(tolua_S,"',v,'");') 157 if flags.t then 158 output(' Mtolua_typeid(tolua_S,typeid(',v,'), "',v,'");') 159 end 160 end 161 end) 164 162 output('}') 165 163 output('\n') … … 191 189 output(pre.."int luaopen_"..self.name.." (lua_State* tolua_S) {") 192 190 output(pre.." return tolua_"..self.name.."_open(tolua_S);") 193 output(pre.."} ;")191 output(pre.."}") 194 192 output("#endif\n\n") 195 193 … … 204 202 205 203 if flags.H then 206 local package_lower = string.lower(self.name) 207 output('#include "'..package_lower..'/'..self.name..'Prereqs.h"\n') 208 output('/* Exported function */') 204 local package_lower = string.lower(self.name) output('#include "'..package_lower..'/'..self.name..'Prereqs.h"\n') output('/* Exported function */') 209 205 output('_'..self.name..'Export') 210 output('int tolua_'..self.name..'_open (lua_State* tolua_S);') 211 output('\n') 206 output('int tolua_'..self.name..'_open (lua_State* tolua_S);') output('\n') 212 207 end 213 208 end … … 224 219 local code = '\n$#include "'..string.lower(flags.n)..'/'..fn..'"\n' 225 220 s= "\n" .. s .. "\n" -- add blank lines as sentinels 226 227 -- eliminate export macro problems in class declarations 228 s = gsub(s, ' _%w*Export ', ' ') 229 230 local _,e,c,t = strfind(s, "\n([^\n]-)[Tt][Oo][Ll][Uu][Aa]_([^%s]*)[^\n]*\n") 221 -- eliminate export macro problems in class declarations s = gsub(s, ' _%w*Export ', ' ') local _,e,c,t = strfind(s, "\n([^\n]-)[Tt][Oo][Ll][Uu][Aa]_([^%s]*)[^\n]*\n") 231 222 while e do 232 223 t = strlower(t) … … 249 240 250 241 -- open input file, if any 242 local st,msg 251 243 if fn then 252 244 local file 253 if flags.f then 254 if string.sub(flags.f, 1, 1) == '/' or string.sub(flags.f, 1, 1) == '\\' or (string.len(flags.f) > 1 and string.sub(flags.f, 2, 2) == ':') then 255 file = flags.f 256 else 257 file = flags.w..'/'..flags.f 258 end 259 else 260 file = flags.f 261 end 262 local st, msg = readfrom(file) 263 if not st then 245 if flags.f then if string.sub(flags.f, 1, 1) == '/' or string.sub(flags.f, 1, 1) == '\\' or (string.len(flags.f) > 1 and string.sub(flags.f, 2, 2) == ':') then file = flags.f else file = flags.w..'/'..flags.f end else file = flags.f end st, msg = readfrom(flags.f) if not st then 264 246 error('#'..msg..' path: '..flags.f) 265 247 end 266 248 local _; _, _, ext = strfind(fn,".*%.(.*)$") 267 249 end 268 local code = "\n" .. read('*a') 269 if ext == 'h' or ext == 'hpp' then 270 code = extract_code(fn,code) 250 local code 251 if ext == 'pkg' then 252 code = prep(st) 253 else 254 code = "\n" .. read('*a') 255 if ext == 'h' or ext == 'hpp' then 256 code = extract_code(fn,code) 257 end 271 258 end 272 259 … … 276 263 end 277 264 278 -- prepare working directory 279 local current_path 280 if not flags.w and flags.f then 281 current_path = gsub(flags.f, '(/)[^/]*%.?[^/]*$', '%1') 282 elseif flags.w then 283 if not (string.sub(flags.w, string.len(flags.w)) == '/') then 284 current_path = flags.w..'/' 285 else 286 current_path = flags.w 287 end 288 else 289 current_path = '' 290 end 291 292 -- deal with include directive 265 -- prepare working directory local current_path if not flags.w and flags.f then current_path = gsub(flags.f, '(/)[^/]*%.?[^/]*$', '%1') elseif flags.w then if not (string.sub(flags.w, string.len(flags.w)) == '/') then current_path = flags.w..'/' else current_path = flags.w end else current_path = '' end -- deal with include directive 293 266 local nsubst 294 267 repeat … … 300 273 error('#'..msg..': '..fn) 301 274 end 275 if kind == 'p' then 276 local s = prep(fp) 277 closefile(fp) 278 return s 279 end 302 280 local s = read(fp,'*a') 303 281 closefile(fp) 304 282 if kind == 'c' or kind == 'h' then 305 283 return extract_code(fn,s) 306 elseif kind == 'p' then307 return "\n\n" .. s308 284 elseif kind == 'l' then 309 285 return "\n$[--##"..fn.."\n" .. s .. "\n$]\n" … … 318 294 end 319 295 end 320 ) 321 until nsubst==0 296 ) until nsubst==0 322 297 323 298 -- deal with renaming directive … … 337 312 338 313 314 setmetatable(_extra_parameters, { __index = _G }) 315 316 function prep(file) 317 318 local chunk = {'local __ret = {"\\n"}\n'} 319 for line in file:lines() do 320 if string.find(line, "^##") then 321 table.insert(chunk, string.sub(line, 3) .. "\n") 322 else 323 local last = 1 324 for text, expr, index in string.gfind(line, "(.-)$(%b())()") do 325 last = index 326 if text ~= "" then 327 table.insert(chunk, string.format('table.insert(__ret, %q )', text)) 328 end 329 table.insert(chunk, string.format('table.insert(__ret, %s )', expr)) 330 end 331 table.insert(chunk, string.format('table.insert(__ret, %q)\n', 332 string.sub(line, last).."\n")) 333 end 334 end 335 table.insert(chunk, '\nreturn table.concat(__ret)\n') 336 local f,e = loadstring(table.concat(chunk)) 337 if e then 338 error("#"..e) 339 end 340 setfenv(f, _extra_parameters) 341 return f() 342 end -
code/branches/pch/src/tolua/lua/variable.lua
r2710 r3127 109 109 if string.find(self.mod, 'tolua_property') then 110 110 111 _,_,type = string.find(self.mod, "tolua_property__([^%s]*)")111 local _,_,type = string.find(self.mod, "tolua_property__([^%s]*)") 112 112 type = type or "default" 113 113 prop_get,prop_set = get_property_methods(type, self.name) … … 131 131 output(' ',self.parent.type,'*','self = ') 132 132 output('(',self.parent.type,'*) ') 133 output('tolua_tousertype(tolua_S,1,0);') 133 local to_func = get_to_function(self.parent.type) 134 output(to_func,'(tolua_S,1,0);') 134 135 elseif static then 135 136 _,_,self.mod = strfind(self.mod,'^%s*static%s%s*(.*)') … … 140 141 if class and static==nil then 141 142 output('#ifndef TOLUA_RELEASE\n') 142 output(' if (!self) tolua_error(tolua_S," invalid \'self\' in accessing variable \''..self.name..'\'",NULL);');143 output(' if (!self) tolua_error(tolua_S,"'..output_error_hook("invalid \'self\' in accessing variable \'%s\'", self.name)..'",NULL);'); 143 144 output('#endif\n') 144 145 end … … 146 147 -- return value 147 148 if string.find(self.mod, 'tolua_inherits') then 149 local push_func = get_push_function(self.type) 148 150 output('#ifdef __cplusplus\n') 149 output(' tolua_pushusertype(tolua_S,(void*)static_cast<'..self.type..'*>(self), "',self.type,'");')151 output(' ',push_func,'(tolua_S,(void*)static_cast<'..self.type..'*>(self), "',self.type,'");') 150 152 output('#else\n') 151 output(' tolua_pushusertype(tolua_S,(void*)(('..self.type..'*)self), "',self.type,'");')153 output(' ',push_func,'(tolua_S,(void*)(('..self.type..'*)self), "',self.type,'");') 152 154 output('#endif\n') 153 155 else … … 156 158 output(' tolua_push'..t..'(tolua_S,(',ct,')'..self:getvalue(class,static,prop_get)..');') 157 159 else 160 local push_func = get_push_function(self.type) 158 161 t = self.type 159 162 if self.ptr == '&' or self.ptr == '' then 160 output(' tolua_pushusertype(tolua_S,(void*)&'..self:getvalue(class,static,prop_get)..',"',t,'");')161 else 162 output(' tolua_pushusertype(tolua_S,(void*)'..self:getvalue(class,static,prop_get)..',"',t,'");')163 output(' ',push_func,'(tolua_S,(void*)&'..self:getvalue(class,static,prop_get)..',"',t,'");') 164 else 165 output(' ',push_func,'(tolua_S,(void*)'..self:getvalue(class,static,prop_get)..',"',t,'");') 163 166 end 164 167 end … … 185 188 output(' ',self.parent.type,'*','self = ') 186 189 output('(',self.parent.type,'*) ') 187 output('tolua_tousertype(tolua_S,1,0);') 190 local to_func = get_to_function(self.parent.type) 191 output(to_func,'(tolua_S,1,0);') 188 192 -- check self value 189 193 end … … 192 196 output(' tolua_Error tolua_err;') 193 197 if class and static==nil then 194 output(' if (!self) tolua_error(tolua_S," invalid \'self\' in accessing variable \''..self.name..'\'",NULL);');198 output(' if (!self) tolua_error(tolua_S,"'..output_error_hook("invalid \'self\' in accessing variable \'%s\'", self.name)..'",NULL);'); 195 199 elseif static then 196 200 _,_,self.mod = strfind(self.mod,'^%s*static%s%s*(.*)') … … 198 202 199 203 -- check variable type 200 output(' if ( !'..self:outchecktype(2)..')')204 output(' if ('..self:outchecktype(2)..')') 201 205 output(' tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err);') 202 206 output('#endif\n') … … 206 210 if self.def ~= '' then def = self.def end 207 211 if self.type == 'char*' and self.dim ~= '' then -- is string 208 output(' strncpy( ')212 output(' strncpy((char*)') 209 213 if class and static then 210 214 output(self.parent.type..'::'..self.name) … … 214 218 output(self.name) 215 219 end 216 output(', tolua_tostring(tolua_S,2,',def,'),',self.dim,'-1);')220 output(',(const char*)tolua_tostring(tolua_S,2,',def,'),',self.dim,'-1);') 217 221 else 218 222 local ptr = '' … … 245 249 output('tolua_to'..t,'(tolua_S,2,',def,'))') 246 250 else 247 output('tolua_tousertype(tolua_S,2,',def,'))') 251 local to_func = get_to_function(self.type) 252 output(to_func,'(tolua_S,2,',def,'))') 248 253 end 249 254 if prop_set then -
code/branches/pch/src/tolua/tolua++.h
r2710 r3127 58 58 #define tolua_pushfieldcppstring(L,lo,idx,s) tolua_pushfieldstring(L, lo, idx, s.c_str()) 59 59 60 #define TEMPLATE_BIND(p) 60 #ifndef TEMPLATE_BIND 61 #define TEMPLATE_BIND(p) 62 #endif 63 61 64 #define TOLUA_TEMPLATE_BIND(p) 65 62 66 #define TOLUA_PROTECTED_DESTRUCTOR 63 67 #define TOLUA_PROPERTY_TYPE(p) … … 79 83 80 84 TOLUA_API const char* tolua_typename (lua_State* L, int lo); 81 TOLUA_API void tolua_error (lua_State* L, c har* msg, tolua_Error* err);85 TOLUA_API void tolua_error (lua_State* L, const char* msg, tolua_Error* err); 82 86 TOLUA_API int tolua_isnoobj (lua_State* L, int lo, tolua_Error* err); 83 87 TOLUA_API int tolua_isvalue (lua_State* L, int lo, int def, tolua_Error* err); 88 TOLUA_API int tolua_isvaluenil (lua_State* L, int lo, tolua_Error* err); 84 89 TOLUA_API int tolua_isboolean (lua_State* L, int lo, int def, tolua_Error* err); 85 90 TOLUA_API int tolua_isnumber (lua_State* L, int lo, int def, tolua_Error* err); … … 110 115 TOLUA_API int tolua_default_collect (lua_State* tolua_S); 111 116 112 TOLUA_API void tolua_usertype (lua_State* L, c har* type);113 TOLUA_API void tolua_beginmodule (lua_State* L, c har* name);117 TOLUA_API void tolua_usertype (lua_State* L, const char* type); 118 TOLUA_API void tolua_beginmodule (lua_State* L, const char* name); 114 119 TOLUA_API void tolua_endmodule (lua_State* L); 115 TOLUA_API void tolua_module (lua_State* L, c har* name, int hasvar);116 TOLUA_API void tolua_class (lua_State* L, c har* name,char* base);117 TOLUA_API void tolua_cclass (lua_State* L, c har* lname, char* name,char* base, lua_CFunction col);118 TOLUA_API void tolua_function (lua_State* L, c har* name, lua_CFunction func);119 TOLUA_API void tolua_constant (lua_State* L, c har* name, doublevalue);120 TOLUA_API void tolua_variable (lua_State* L, c har* name, lua_CFunction get, lua_CFunction set);121 TOLUA_API void tolua_array (lua_State* L,c har* name, lua_CFunction get, lua_CFunction set);120 TOLUA_API void tolua_module (lua_State* L, const char* name, int hasvar); 121 TOLUA_API void tolua_class (lua_State* L, const char* name, const char* base); 122 TOLUA_API void tolua_cclass (lua_State* L, const char* lname, const char* name, const char* base, lua_CFunction col); 123 TOLUA_API void tolua_function (lua_State* L, const char* name, lua_CFunction func); 124 TOLUA_API void tolua_constant (lua_State* L, const char* name, lua_Number value); 125 TOLUA_API void tolua_variable (lua_State* L, const char* name, lua_CFunction get, lua_CFunction set); 126 TOLUA_API void tolua_array (lua_State* L,const char* name, lua_CFunction get, lua_CFunction set); 122 127 123 128 /* TOLUA_API void tolua_set_call_event(lua_State* L, lua_CFunction func, char* type); */ … … 126 131 TOLUA_API void tolua_pushvalue (lua_State* L, int lo); 127 132 TOLUA_API void tolua_pushboolean (lua_State* L, int value); 128 TOLUA_API void tolua_pushnumber (lua_State* L, doublevalue);133 TOLUA_API void tolua_pushnumber (lua_State* L, lua_Number value); 129 134 TOLUA_API void tolua_pushstring (lua_State* L, const char* value); 130 135 TOLUA_API void tolua_pushuserdata (lua_State* L, void* value); … … 133 138 TOLUA_API void tolua_pushfieldvalue (lua_State* L, int lo, int index, int v); 134 139 TOLUA_API void tolua_pushfieldboolean (lua_State* L, int lo, int index, int v); 135 TOLUA_API void tolua_pushfieldnumber (lua_State* L, int lo, int index, doublev);140 TOLUA_API void tolua_pushfieldnumber (lua_State* L, int lo, int index, lua_Number v); 136 141 TOLUA_API void tolua_pushfieldstring (lua_State* L, int lo, int index, const char* v); 137 142 TOLUA_API void tolua_pushfielduserdata (lua_State* L, int lo, int index, void* v); … … 139 144 TOLUA_API void tolua_pushfieldusertype_and_takeownership (lua_State* L, int lo, int index, void* v, const char* type); 140 145 141 TOLUA_API double tolua_tonumber (lua_State* L, int narg, doubledef);146 TOLUA_API lua_Number tolua_tonumber (lua_State* L, int narg, lua_Number def); 142 147 TOLUA_API const char* tolua_tostring (lua_State* L, int narg, const char* def); 143 148 TOLUA_API void* tolua_touserdata (lua_State* L, int narg, void* def); … … 145 150 TOLUA_API int tolua_tovalue (lua_State* L, int narg, int def); 146 151 TOLUA_API int tolua_toboolean (lua_State* L, int narg, int def); 147 TOLUA_API double tolua_tofieldnumber (lua_State* L, int lo, int index, doubledef);152 TOLUA_API lua_Number tolua_tofieldnumber (lua_State* L, int lo, int index, lua_Number def); 148 153 TOLUA_API const char* tolua_tofieldstring (lua_State* L, int lo, int index, const char* def); 149 154 TOLUA_API void* tolua_tofielduserdata (lua_State* L, int lo, int index, void* def); … … 176 181 TOLUA_API int tolua_fast_isa(lua_State *L, int mt_indexa, int mt_indexb, int super_index); 177 182 183 #ifndef Mtolua_new 184 #define Mtolua_new(EXP) new EXP 185 #endif 186 187 #ifndef Mtolua_delete 188 #define Mtolua_delete(EXP) delete EXP 189 #endif 190 191 #ifndef Mtolua_new_dim 192 #define Mtolua_new_dim(EXP, len) new EXP[len] 193 #endif 194 195 #ifndef Mtolua_delete_dim 196 #define Mtolua_delete_dim(EXP) delete [] EXP 197 #endif 198 199 #ifndef tolua_outside 200 #define tolua_outside 201 #endif 202 203 #ifndef tolua_owned 204 #define tolua_owned 205 #endif 206 178 207 #ifdef __cplusplus 179 208 } -
code/branches/pch/src/tolua/tolua.c
r2710 r3127 50 50 " -E value[=value] : add extra values to the luastate\n" 51 51 " -t : export a list of types asociates with the C++ typeid name\n" 52 " -q : don't print warnings to the console\n" 52 53 " -h : print this message.\n" 53 54 "Should the input file be omitted, stdin is assumed;\n" … … 149 150 case 'E': add_extra(L,argv[++i]); break; 150 151 case 't': setfield(L,t,"t",""); break; 152 case 'q': setfield(L,t,"q",""); break; 151 153 default: error(argv[i]); break; 152 154 } -
code/branches/pch/src/tolua/tolua_event.c
r1505 r3127 372 372 static int class_eq_event (lua_State* L) 373 373 { 374 return do_operator(L,".eq"); 374 /* copying code from do_operator here to return false when no operator is found */ 375 if (lua_isuserdata(L,1)) 376 { 377 /* Try metatables */ 378 lua_pushvalue(L,1); /* stack: op1 op2 */ 379 while (lua_getmetatable(L,-1)) 380 { /* stack: op1 op2 op1 mt */ 381 lua_remove(L,-2); /* stack: op1 op2 mt */ 382 lua_pushstring(L,".eq"); /* stack: op1 op2 mt key */ 383 lua_rawget(L,-2); /* stack: obj key mt func */ 384 if (lua_isfunction(L,-1)) 385 { 386 lua_pushvalue(L,1); 387 lua_pushvalue(L,2); 388 lua_call(L,2,1); 389 return 1; 390 } 391 lua_settop(L,3); 392 } 393 } 394 395 lua_settop(L, 3); 396 lua_pushboolean(L, 0); 397 return 1; 375 398 } 376 399 -
code/branches/pch/src/tolua/tolua_is.c
r2710 r3127 86 86 } 87 87 88 TOLUA_API void tolua_error (lua_State* L, c har* msg, tolua_Error* err)88 TOLUA_API void tolua_error (lua_State* L, const char* msg, tolua_Error* err) 89 89 { 90 90 if (msg[0] == '#') … … 117 117 118 118 /* the equivalent of lua_is* for usertable */ 119 static int lua_isusertable (lua_State* L, int lo, const c har* type)119 static int lua_isusertable (lua_State* L, int lo, const const char* type) 120 120 { 121 121 int r = 0; … … 213 213 return 0; 214 214 } 215 216 TOLUA_API int tolua_isboolean (lua_State* L, int lo, int def, tolua_Error* err) 217 { 218 if (def && lua_gettop(L)<abs(lo)) 219 return 1; 220 if (lua_isnil(L,lo) || lua_isboolean(L,lo)) 221 return 1; 222 err->index = lo; 223 err->array = 0; 224 err->type = "boolean"; 225 return 0; 226 } 227 228 TOLUA_API int tolua_isnumber (lua_State* L, int lo, int def, tolua_Error* err) 229 { 230 if (def && lua_gettop(L)<abs(lo)) 231 return 1; 232 if (lua_isnumber(L,lo)) 233 return 1; 234 err->index = lo; 235 err->array = 0; 236 err->type = "number"; 237 return 0; 238 } 239 240 TOLUA_API int tolua_isstring (lua_State* L, int lo, int def, tolua_Error* err) 241 { 242 if (def && lua_gettop(L)<abs(lo)) 243 return 1; 244 if (lua_isnil(L,lo) || lua_isstring(L,lo)) 245 return 1; 246 err->index = lo; 247 err->array = 0; 248 err->type = "string"; 249 return 0; 250 } 251 252 TOLUA_API int tolua_istable (lua_State* L, int lo, int def, tolua_Error* err) 253 { 254 if (def && lua_gettop(L)<abs(lo)) 255 return 1; 256 if (lua_istable(L,lo)) 257 return 1; 258 err->index = lo; 259 err->array = 0; 260 err->type = "table"; 261 return 0; 262 } 263 264 TOLUA_API int tolua_isusertable (lua_State* L, int lo, const char* type, int def, tolua_Error* err) 265 { 266 if (def && lua_gettop(L)<abs(lo)) 267 return 1; 268 if (lua_isusertable(L,lo,type)) 269 return 1; 270 err->index = lo; 271 err->array = 0; 272 err->type = type; 273 return 0; 274 } 275 276 277 TOLUA_API int tolua_isuserdata (lua_State* L, int lo, int def, tolua_Error* err) 278 { 279 if (def && lua_gettop(L)<abs(lo)) 280 return 1; 281 if (lua_isnil(L,lo) || lua_isuserdata(L,lo)) 282 return 1; 283 err->index = lo; 284 err->array = 0; 285 err->type = "userdata"; 286 return 0; 287 } 288 289 TOLUA_API int tolua_isvaluenil (lua_State* L, int lo, tolua_Error* err) { 290 291 if (lua_gettop(L)<abs(lo)) 292 return 0; /* somebody else should chack this */ 293 if (!lua_isnil(L, lo)) 294 return 0; 295 296 err->index = lo; 297 err->array = 0; 298 err->type = "value"; 299 return 1; 300 }; 301 215 302 TOLUA_API int tolua_isvalue (lua_State* L, int lo, int def, tolua_Error* err) 216 303 { … … 220 307 err->array = 0; 221 308 err->type = "value"; 222 return 0;223 }224 225 TOLUA_API int tolua_isboolean (lua_State* L, int lo, int def, tolua_Error* err)226 {227 if (def && lua_gettop(L)<abs(lo))228 return 1;229 if (lua_isnil(L,lo) || lua_isboolean(L,lo))230 return 1;231 err->index = lo;232 err->array = 0;233 err->type = "boolean";234 return 0;235 }236 237 TOLUA_API int tolua_isnumber (lua_State* L, int lo, int def, tolua_Error* err)238 {239 if (def && lua_gettop(L)<abs(lo))240 return 1;241 if (lua_isnumber(L,lo))242 return 1;243 err->index = lo;244 err->array = 0;245 err->type = "number";246 return 0;247 }248 249 TOLUA_API int tolua_isstring (lua_State* L, int lo, int def, tolua_Error* err)250 {251 if (def && lua_gettop(L)<abs(lo))252 return 1;253 if (lua_isnil(L,lo) || lua_isstring(L,lo))254 return 1;255 err->index = lo;256 err->array = 0;257 err->type = "string";258 return 0;259 }260 261 TOLUA_API int tolua_istable (lua_State* L, int lo, int def, tolua_Error* err)262 {263 if (def && lua_gettop(L)<abs(lo))264 return 1;265 if (lua_istable(L,lo))266 return 1;267 err->index = lo;268 err->array = 0;269 err->type = "table";270 return 0;271 }272 273 TOLUA_API int tolua_isusertable (lua_State* L, int lo, const char* type, int def, tolua_Error* err)274 {275 if (def && lua_gettop(L)<abs(lo))276 return 1;277 if (lua_isusertable(L,lo,type))278 return 1;279 err->index = lo;280 err->array = 0;281 err->type = type;282 return 0;283 }284 285 286 TOLUA_API int tolua_isuserdata (lua_State* L, int lo, int def, tolua_Error* err)287 {288 if (def && lua_gettop(L)<abs(lo))289 return 1;290 if (lua_isnil(L,lo) || lua_isuserdata(L,lo))291 return 1;292 err->index = lo;293 err->array = 0;294 err->type = "userdata";295 309 return 0; 296 310 } -
code/branches/pch/src/tolua/tolua_map.c
r2710 r3127 390 390 * It maps 'const type' as being also a 'type' 391 391 */ 392 TOLUA_API void tolua_usertype (lua_State* L, c har* type)392 TOLUA_API void tolua_usertype (lua_State* L, const char* type) 393 393 { 394 394 char ctype[128] = "const "; … … 404 404 * It pushes the module (or class) table on the stack 405 405 */ 406 TOLUA_API void tolua_beginmodule (lua_State* L, c har* name)406 TOLUA_API void tolua_beginmodule (lua_State* L, const char* name) 407 407 { 408 408 if (name) … … 427 427 */ 428 428 #if 1 429 TOLUA_API void tolua_module (lua_State* L, c har* name, int hasvar)429 TOLUA_API void tolua_module (lua_State* L, const char* name, int hasvar) 430 430 { 431 431 if (name) … … 463 463 } 464 464 #else 465 TOLUA_API void tolua_module (lua_State* L, c har* name, int hasvar)465 TOLUA_API void tolua_module (lua_State* L, const char* name, int hasvar) 466 466 { 467 467 if (name) … … 519 519 * It maps a C class, setting the appropriate inheritance and super classes. 520 520 */ 521 TOLUA_API void tolua_cclass (lua_State* L, c har* lname, char* name,char* base, lua_CFunction col)521 TOLUA_API void tolua_cclass (lua_State* L, const char* lname, const char* name, const char* base, lua_CFunction col) 522 522 { 523 523 char cname[128] = "const "; … … 578 578 * It assigns a function into the current module (or class) 579 579 */ 580 TOLUA_API void tolua_function (lua_State* L, c har* name, lua_CFunction func)580 TOLUA_API void tolua_function (lua_State* L, const char* name, lua_CFunction func) 581 581 { 582 582 lua_pushstring(L,name); … … 601 601 * It assigns a constant number into the current module (or class) 602 602 */ 603 TOLUA_API void tolua_constant (lua_State* L, c har* name, doublevalue)603 TOLUA_API void tolua_constant (lua_State* L, const char* name, lua_Number value) 604 604 { 605 605 lua_pushstring(L,name); … … 612 612 * It assigns a variable into the current module (or class) 613 613 */ 614 TOLUA_API void tolua_variable (lua_State* L, c har* name, lua_CFunction get, lua_CFunction set)614 TOLUA_API void tolua_variable (lua_State* L, const char* name, lua_CFunction get, lua_CFunction set) 615 615 { 616 616 /* get func */ … … 664 664 * It assigns an array into the current module (or class) 665 665 */ 666 TOLUA_API void tolua_array (lua_State* L, c har* name, lua_CFunction get, lua_CFunction set)666 TOLUA_API void tolua_array (lua_State* L, const char* name, lua_CFunction get, lua_CFunction set) 667 667 { 668 668 lua_pushstring(L,".get"); -
code/branches/pch/src/tolua/tolua_push.c
r2710 r3127 28 28 } 29 29 30 TOLUA_API void tolua_pushnumber (lua_State* L, doublevalue)30 TOLUA_API void tolua_pushnumber (lua_State* L, lua_Number value) 31 31 { 32 32 lua_pushnumber(L,value); … … 134 134 135 135 136 TOLUA_API void tolua_pushfieldnumber (lua_State* L, int lo, int index, doublev)136 TOLUA_API void tolua_pushfieldnumber (lua_State* L, int lo, int index, lua_Number v) 137 137 { 138 138 lua_pushnumber(L,index); -
code/branches/pch/src/tolua/tolua_to.c
r1505 r3127 18 18 #include <stdlib.h> 19 19 20 TOLUA_API double tolua_tonumber (lua_State* L, int narg, doubledef)20 TOLUA_API lua_Number tolua_tonumber (lua_State* L, int narg, lua_Number def) 21 21 { 22 22 return lua_gettop(L)<abs(narg) ? def : lua_tonumber(L,narg); … … 72 72 } 73 73 74 TOLUA_API double tolua_tofieldnumber (lua_State* L, int lo, int index, doubledef)74 TOLUA_API lua_Number tolua_tofieldnumber (lua_State* L, int lo, int index, lua_Number def) 75 75 { 76 76 double v;
Note: See TracChangeset
for help on using the changeset viewer.