summaryrefslogtreecommitdiffstats
path: root/lib/tolua++/src/bin/lua/custom.lua
blob: de5912fb31681c3a4a7e3bcfa93ef38554767b20 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

function extract_code(fn,s)
	local code = ""
	if fn then
		code = '\n$#include "'..fn..'"\n'
	end
	s= "\n" .. s .. "\n" -- add blank lines as sentinels
	local _,e,c,t = strfind(s, "\n([^\n]-)SCRIPT_([%w_]*)[^\n]*\n")
	while e do
		t = strlower(t)
		if t == "bind_begin" then
			_,e,c = strfind(s,"(.-)\n[^\n]*SCRIPT_BIND_END[^\n]*\n",e)
			if not e then
			 tolua_error("Unbalanced 'SCRIPT_BIND_BEGIN' directive in header file")
			end
		end
		if t == "bind_class" or t == "bind_block" then
			local b
			_,e,c,b = string.find(s, "([^{]-)(%b{})", e)
			c = c..'{\n'..extract_code(nil, b)..'\n};\n'
		end
		code = code .. c .. "\n"
	 _,e,c,t = strfind(s, "\n([^\n]-)SCRIPT_([%w_]*)[^\n]*\n",e)
	end
	return code
end

function preprocess_hook(p)
end

function preparse_hook(p)
end

function include_file_hook(p, filename)
	do return end
--print("FILENAME is "..filename)
	p.code = string.gsub(p.code, "\n%s*SigC::Signal", "\n\ttolua_readonly SigC::Signal")
	p.code = string.gsub(p.code, "#ifdef __cplusplus\nextern \"C\" {\n#endif", "")
	p.code = string.gsub(p.code, "#ifdef __cplusplus\n};?\n#endif", "")
	p.code = string.gsub(p.code, "DECLSPEC", "")
	p.code = string.gsub(p.code, "SDLCALL", "")
	p.code = string.gsub(p.code, "DLLINTERFACE", "")
	p.code = string.gsub(p.code, "#define[^\n]*_[hH]_?%s*\n", "\n")
--print("code is "..p.code)
end