- Timestamp:
- Jun 9, 2009, 7:44:46 PM (15 years ago)
- Location:
- code/branches/pch/src/tolua/lua
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pch/src/tolua/lua/basic.lua
r3127 r3129 377 377 378 378 -- called to output an error message 379 function output_error_hook( ...)380 return string.format( ...)379 function output_error_hook(str, arg) 380 return string.format(str, arg) 381 381 end 382 382 -
code/branches/pch/src/tolua/lua/package.lua
r3127 r3129 42 42 return "\n#["..getn(L).."]#" 43 43 end 44 ) -- avoid preprocessing embedded C code 44 ) 45 -- avoid preprocessing embedded C code 45 46 local C = {} 46 47 self.code = gsub(self.code,"\n%s*%$%<","\3") -- deal with embedded C code … … 50 51 return "\n#<"..getn(C)..">#" 51 52 end 52 ) -- avoid preprocessing embedded C code 53 ) 54 -- avoid preprocessing embedded C code 53 55 self.code = gsub(self.code,"\n%s*%$%{","\5") -- deal with embedded C code 54 56 self.code = gsub(self.code,"\n%s*%$%}","\6") … … 58 60 end 59 61 ) 62 60 63 --self.code = gsub(self.code,"\n%s*#[^d][^\n]*\n", "\n\n") -- eliminate preprocessor directives that don't start with 'd' 61 64 self.code = gsub(self.code,"\n[ \t]*#[ \t]*[^d%<%[]", "\n//") -- eliminate preprocessor directives that don't start with 'd' … … 68 71 end 69 72 ) 73 70 74 -- perform global substitution 71 75 … … 90 94 return L[tonumber(n)] 91 95 end 92 ) -- restore embedded C code 96 ) 97 -- restore embedded C code 93 98 self.code = gsub(self.code,"%#%<(%d+)%>%#", function (n) 94 99 return C[tonumber(n)] 95 100 end 96 ) -- restore verbatim lines 101 ) 102 -- restore verbatim lines 97 103 self.code = gsub(self.code,"%#(%d+)%#", function (n) 98 104 return V[tonumber(n)] 99 105 end 100 106 ) 107 101 108 self.code = string.gsub(self.code, "\n%s*%$([^\n]+)", function (l) 102 109 Verbatim(l.."\n") 103 110 return "\n" 104 111 end 105 )end 112 ) 113 end 114 106 115 -- translate verbatim 107 116 function classPackage:preamble () … … 160 169 end 161 170 end) 162 171 output('}') 163 172 output('\n') 164 173 end … … 189 198 output(pre.."int luaopen_"..self.name.." (lua_State* tolua_S) {") 190 199 output(pre.." return tolua_"..self.name.."_open(tolua_S);") 191 output(pre.."} ")200 output(pre.."};") 192 201 output("#endif\n\n") 193 202 … … 202 211 203 212 if flags.H then 204 local package_lower = string.lower(self.name) output('#include "'..package_lower..'/'..self.name..'Prereqs.h"\n') output('/* Exported function */') 213 local package_lower = string.lower(self.name) 214 output('#include "'..package_lower..'/'..self.name..'Prereqs.h"\n') 215 output('/* Exported function */') 205 216 output('_'..self.name..'Export') 206 output('int tolua_'..self.name..'_open (lua_State* tolua_S);') output('\n') 217 output('int tolua_'..self.name..'_open (lua_State* tolua_S);') 218 output('\n') 207 219 end 208 220 end … … 219 231 local code = '\n$#include "'..string.lower(flags.n)..'/'..fn..'"\n' 220 232 s= "\n" .. s .. "\n" -- add blank lines as sentinels 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") 233 234 -- eliminate export macro problems in class declarations 235 s = gsub(s, ' _%w*Export ', ' ') 236 237 local _,e,c,t = strfind(s, "\n([^\n]-)[Tt][Oo][Ll][Uu][Aa]_([^%s]*)[^\n]*\n") 222 238 while e do 223 239 t = strlower(t) … … 243 259 if fn then 244 260 local file 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 261 if flags.f then 262 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 263 file = flags.f 264 else 265 file = flags.w..'/'..flags.f 266 end 267 else 268 file = flags.f 269 end 270 st, msg = readfrom(file) 271 if not st then 246 272 error('#'..msg..' path: '..flags.f) 247 273 end … … 263 289 end 264 290 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 291 -- prepare working directory 292 local current_path 293 if not flags.w and flags.f then 294 current_path = gsub(flags.f, '(/)[^/]*%.?[^/]*$', '%1') 295 elseif flags.w then 296 if not (string.sub(flags.w, string.len(flags.w)) == '/') then 297 current_path = flags.w..'/' 298 else 299 current_path = flags.w 300 end 301 else 302 current_path = '' 303 end 304 305 -- deal with include directive 266 306 local nsubst 267 307 repeat … … 294 334 end 295 335 end 296 ) until nsubst==0 336 ) 337 until nsubst==0 297 338 298 339 -- deal with renaming directive … … 318 359 local chunk = {'local __ret = {"\\n"}\n'} 319 360 for line in file:lines() do 320 if string.find(line, "^##") then321 table.insert(chunk, string.sub(line, 3) .. "\n")322 else323 local last = 1324 for text, expr, index in string.gfind(line, "(.-)$(%b())()") do325 last = index326 if text ~= "" then327 table.insert(chunk, string.format('table.insert(__ret, %q )', text))328 end329 table.insert(chunk, string.format('table.insert(__ret, %s )', expr))330 end331 table.insert(chunk, string.format('table.insert(__ret, %q)\n',332 string.sub(line, last).."\n"))333 end361 if string.find(line, "^##") then 362 table.insert(chunk, string.sub(line, 3) .. "\n") 363 else 364 local last = 1 365 for text, expr, index in string.gfind(line, "(.-)$(%b())()") do 366 last = index 367 if text ~= "" then 368 table.insert(chunk, string.format('table.insert(__ret, %q )', text)) 369 end 370 table.insert(chunk, string.format('table.insert(__ret, %s )', expr)) 371 end 372 table.insert(chunk, string.format('table.insert(__ret, %q)\n', 373 string.sub(line, last).."\n")) 374 end 334 375 end 335 376 table.insert(chunk, '\nreturn table.concat(__ret)\n')
Note: See TracChangeset
for help on using the changeset viewer.