Changeset 3138 for code/branches/pch/src/tolua/lua/package.lua
- Timestamp:
- Jun 10, 2009, 4:01:42 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pch/src/tolua/lua/package.lua
r3129 r3138 146 146 output('{') 147 147 output(' '..i..'* self = ('..i..'*) tolua_tousertype(tolua_S,1,0);') 148 output(' Mtolua_delete(self);')148 output(' delete self;') 149 149 output(' return 0;') 150 150 output('}') … … 157 157 output('static void tolua_reg_types (lua_State* tolua_S)') 158 158 output('{') 159 159 foreach(_usertype,function(n,v) output(' tolua_usertype(tolua_S,"',v,'");') end) 160 160 if flags.t then 161 161 output("#ifndef Mtolua_typeid\n#define Mtolua_typeid(L,TI,T)\n#endif\n") 162 end 163 foreach(_usertype,function(n,v) 164 if (not _global_classes[v]) or _global_classes[v]:check_public_access() then 165 output(' tolua_usertype(tolua_S,"',v,'");') 166 if flags.t then 167 output(' Mtolua_typeid(tolua_S,typeid(',v,'), "',v,'");') 168 end 169 end 170 end) 171 output('}') 162 foreach(_usertype,function(n,v) output(' Mtolua_typeid(tolua_S,typeid(',v,'), "',v,'");') end) 163 end 164 output('}') 172 165 output('\n') 173 166 end … … 256 249 257 250 -- open input file, if any 258 local st,msg259 251 if fn then 260 252 local file … … 268 260 file = flags.f 269 261 end 270 st, msg = readfrom(file)262 local st, msg = readfrom(file) 271 263 if not st then 272 264 error('#'..msg..' path: '..flags.f) … … 274 266 local _; _, _, ext = strfind(fn,".*%.(.*)$") 275 267 end 276 local code 277 if ext == 'pkg' then 278 code = prep(st) 279 else 280 code = "\n" .. read('*a') 281 if ext == 'h' or ext == 'hpp' then 282 code = extract_code(fn,code) 283 end 268 local code = "\n" .. read('*a') 269 if ext == 'h' or ext == 'hpp' then 270 code = extract_code(fn,code) 284 271 end 285 272 … … 313 300 error('#'..msg..': '..fn) 314 301 end 315 if kind == 'p' then316 local s = prep(fp)317 closefile(fp)318 return s319 end320 302 local s = read(fp,'*a') 321 303 closefile(fp) 322 304 if kind == 'c' or kind == 'h' then 323 305 return extract_code(fn,s) 306 elseif kind == 'p' then 307 return "\n\n" .. s 324 308 elseif kind == 'l' then 325 309 return "\n$[--##"..fn.."\n" .. s .. "\n$]\n" … … 353 337 354 338 355 setmetatable(_extra_parameters, { __index = _G })356 357 function prep(file)358 359 local chunk = {'local __ret = {"\\n"}\n'}360 for line in file:lines() do361 if string.find(line, "^##") then362 table.insert(chunk, string.sub(line, 3) .. "\n")363 else364 local last = 1365 for text, expr, index in string.gfind(line, "(.-)$(%b())()") do366 last = index367 if text ~= "" then368 table.insert(chunk, string.format('table.insert(__ret, %q )', text))369 end370 table.insert(chunk, string.format('table.insert(__ret, %s )', expr))371 end372 table.insert(chunk, string.format('table.insert(__ret, %q)\n',373 string.sub(line, last).."\n"))374 end375 end376 table.insert(chunk, '\nreturn table.concat(__ret)\n')377 local f,e = loadstring(table.concat(chunk))378 if e then379 error("#"..e)380 end381 setfenv(f, _extra_parameters)382 return f()383 end
Note: See TracChangeset
for help on using the changeset viewer.