This repository has been archived by the owner on Nov 20, 2020. It is now read-only.
forked from Neopallium/LuaNativeObjects
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gen_simple.lua
78 lines (75 loc) · 2.42 KB
/
gen_simple.lua
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
-- Copyright (c) 2010 by Robert G. Jakabosky <bobby@neoawareness.com>
--
-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the "Software"), to deal
-- in the Software without restriction, including without limitation the rights
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in
-- all copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-- THE SOFTWARE.
--
-- dump info
--
--[[
print"============ Dump types ================="
for k,v in pairs(types) do
local lang_type = v.lang_type
if lang_type == nil then
lang_type = 'userdata'
end
print(v.c_type .. '\t(' .. k .. ')' .. '\tlua: ' .. lang_type)
end
]]
print"============ Dump objects ================="
local function find_ret(rec)
for i=1,#rec do
local v = rec[i]
if is_record(v) and v._rec_type == 'var_out' then
return v;
end
end
return { c_type = "void" }
end
process_records{
object = function(self, rec, parent)
print("object " .. rec.name .. "{")
--print(dump(rec))
end,
property = function(self, rec, parent)
print(rec.c_type .. " " .. rec.name .. "; /* is='" .. rec.is .. "', isa='" .. rec.isa .. "' */")
end,
include = function(self, rec, parent)
print('#include "' .. rec.file .. '"')
end,
option = function(self, rec, parent)
print("/* option: " .. rec.name .. " */")
end,
object_end = function(self, rec, parent)
print("}\n")
end,
c_function = function(self, rec, parent)
local ret = find_ret(rec)
io.write(ret.c_type .. " " .. rec.name .. "(")
end,
c_function_end = function(self, rec, parent)
print(")")
end,
var_in = function(self, rec, parent)
if parent._first_var ~= nil then
io.write(', ')
else
parent._first_var = true
end
io.write(rec.c_type .. " " .. rec.name)
end,
}