elua: generate __properties in lualian

This commit is contained in:
Daniel Kolesa 2014-10-17 16:44:08 +01:00
parent 54d7fed7b6
commit 6311472e97
1 changed files with 49 additions and 3 deletions

View File

@ -132,20 +132,47 @@ local Node = util.Object:clone {
gen_children = function(self, s)
local len = #self.children
local evs = self.events
local evs = self.events
local evslen
if evs then evslen = #evs end
local hasevs = evs and evslen > 0
local hasprops = false
local nprops = 0
local props = {}
for i, v in ipairs(self.children) do
v.parent_node = self
v:generate(s, (not hasevs) and (i == len))
if v.generate_prop then
if v:generate_prop(props) then
nprops = nprops + 1
end
hasprops = true
end
v:generate(s, (not hasevs) and (not hasprops) and (i == len))
end
if hasevs then
s:write(" __events = {\n")
for i, v in ipairs(evs) do
v.parent_node = self
v:generate(s, i == evslen)
end
s:write(" }", hasprops and "," or "", "\n")
end
if hasprops then
if hasevs then
s:write("\n")
end
s:write(" __properties = {\n")
local pi = 0
for k, v in pairs(props) do
pi = pi + 1
s:write(" [\"", k, "\"] = { ", table.concat(v, ", "),
" }", pi ~= nprops and "," or "", "\n")
end
s:write(" }\n")
end
end
@ -255,7 +282,9 @@ local Property = Method:clone {
local proto = {
name = prop:name_get(),
suffix = (self.isget and "_get" or "_set")
suffix = (self.isget and "_get" or "_set"),
nkeys = #keys,
nvals = #vals
}
proto.ret_type = rett and rett:c_type_get() or "void"
local args, cargs, vargs = { "self" }, {}, {}
@ -320,6 +349,23 @@ local Property = Method:clone {
self.cached_proto = proto
return proto
end,
generate_prop = function(self, props)
local proto = self:gen_proto()
local prop = props[proto.name]
if prop then
if self.isget then
prop[3] = "true"
else
prop[4] = "true"
end
return false
else
props[proto.name] = { proto.nkeys, math.max(proto.nvals, 1),
tostring(self.isget), tostring(not self.isget) }
return true
end
end
}