Debian Codegraph @

3rdparty/toluapp/src/bin/lua/custom.lua

raw
1
2 function extract_code(fn,s)
3 local code = ""
4 if fn then
5 code = '\n$#include "'..fn..'"\n'
6 end
7 s= "\n" .. s .. "\n" -- add blank lines as sentinels
8 local _,e,c,t = strfind(s, "\n([^\n]-)SCRIPT_([%w_]*)[^\n]*\n")
9 while e do
10 t = strlower(t)
11 if t == "bind_begin" then
12 _,e,c = strfind(s,"(.-)\n[^\n]*SCRIPT_BIND_END[^\n]*\n",e)
13 if not e then
14 tolua_error("Unbalanced 'SCRIPT_BIND_BEGIN' directive in header file")
15 end
16 end
17 if t == "bind_class" or t == "bind_block" then
18 local b
19 _,e,c,b = string.find(s, "([^{]-)(%b{})", e)
20 c = c..'{\n'..extract_code(nil, b)..'\n};\n'
21 end
22 code = code .. c .. "\n"
23 _,e,c,t = strfind(s, "\n([^\n]-)SCRIPT_([%w_]*)[^\n]*\n",e)
24 end
25 return code
26 end
27
28 function preprocess_hook(p)
29 end
30
31 function preparse_hook(p)
32 end
33
34 function include_file_hook(p, filename)
35 do return end
36 --print("FILENAME is "..filename)
37 p.code = string.gsub(p.code, "\n%s*SigC::Signal", "\n\ttolua_readonly SigC::Signal")
38 p.code = string.gsub(p.code, "#ifdef __cplusplus\nextern \"C\" {\n#endif", "")
39 p.code = string.gsub(p.code, "#ifdef __cplusplus\n};?\n#endif", "")
40 p.code = string.gsub(p.code, "DECLSPEC", "")
41 p.code = string.gsub(p.code, "SDLCALL", "")
42 p.code = string.gsub(p.code, "DLLINTERFACE", "")
43 p.code = string.gsub(p.code, "#define[^\n]*_[hH]_?%s*\n", "\n")
44 --print("code is "..p.code)
45 end