wip allow inheriting object method types
This commit is contained in:
@@ -151,13 +151,21 @@ end
|
||||
local function arglistToTs(args)
|
||||
return map(args, valToTs)
|
||||
end
|
||||
function bl.type(name,typ)
|
||||
function bl.type(name, typ)
|
||||
if typ~='bool' and typ~='boolean' and typ~='object' and typ~=nil then
|
||||
error('bl.type: can only set type to \'bool\' or \'object\' or nil', 2) end
|
||||
if not isValidFuncNameNsArgn(name) then
|
||||
error('bl.type: invalid function or variable name \''..name..'\'', 2) end
|
||||
if typ=='bool' then typ='boolean' end
|
||||
|
||||
bl._forceType[name:lower()] = typ
|
||||
-- apply to children (wip)
|
||||
--local class, rest = name:match('^([a-zA-Z0-9_]+)(::.+)$')
|
||||
--if not class then
|
||||
-- class, rest = name:match('^([a-zA-Z0-9_]+)(%..+)$') end
|
||||
--if class then
|
||||
--
|
||||
--end
|
||||
end
|
||||
|
||||
|
||||
@@ -199,6 +207,12 @@ function bl.isFunction(a1, a2)
|
||||
end
|
||||
|
||||
-- Torque object pseudo-class
|
||||
local tsClassMeta = {
|
||||
__tostring = function(t)
|
||||
return 'torqueClass:'..t._name..
|
||||
(t._inherit and (':'..t._inherit) or '')
|
||||
end,
|
||||
}
|
||||
bl._objectUserMetas = bl._objectUserMetas or {}
|
||||
function bl.class(name, inherit)
|
||||
if not ( type(name)=='string' and isValidFuncName(name) ) then
|
||||
@@ -207,9 +221,13 @@ function bl.class(name, inherit)
|
||||
error('bl.class: argument #2: inherit name must be a string or nil', 2) end
|
||||
name = name:lower()
|
||||
|
||||
local met = bl._objectUserMetas[name] or {}
|
||||
local met = bl._objectUserMetas[name] or {
|
||||
_name = name,
|
||||
_inherit = nil,
|
||||
_children = {},
|
||||
}
|
||||
bl._objectUserMetas[name] = met
|
||||
met._name = name
|
||||
setmetatable(met, tsClassMeta)
|
||||
|
||||
if inherit then
|
||||
inherit = inherit:lower()
|
||||
@@ -218,12 +236,14 @@ function bl.class(name, inherit)
|
||||
if not inh then error('bl.class: argument #2: \''..inherit..'\' is not the '..
|
||||
'name of an existing class', 2) end
|
||||
|
||||
local inhI = bl._objectUserMetas[name]._inherit
|
||||
inh._children[name] = true
|
||||
|
||||
local inhI = met._inherit
|
||||
if inhI and inhI~=inh then
|
||||
error('bl.class: argument #2: class already exists and '..
|
||||
'inherits a different parent.', 2) end
|
||||
|
||||
bl._objectUserMetas[name]._inherit = inh
|
||||
met._inherit = inh
|
||||
end
|
||||
end
|
||||
local function objectInheritedMetas(name)
|
||||
@@ -418,7 +438,7 @@ toTsObject = function(idiS)
|
||||
_tsObjectId = _bllua_ts.callobj(idiS, 'getId' ),
|
||||
_tsName = _bllua_ts.callobj(idiS, 'getName' ),
|
||||
_tsNamespace = className,
|
||||
_tsClassName = className:lower()
|
||||
_tsClassName = className:lower(),
|
||||
}
|
||||
setmetatable(obj, tsObjectMeta)
|
||||
|
||||
@@ -438,7 +458,7 @@ local tsMeta = {
|
||||
__index = function(t, name)
|
||||
if getmetatable(t)[name] then
|
||||
return getmetatable(t)[name]
|
||||
elseif bl._objectUserMetas[name:lower()] then
|
||||
elseif type(name)=='string' and bl._objectUserMetas[name:lower()] then
|
||||
return bl._objectUserMetas[name:lower()]
|
||||
else
|
||||
if type(name)=='number' then
|
||||
@@ -491,7 +511,7 @@ function bl.tobool(val)
|
||||
--val~='0' and
|
||||
val~=0
|
||||
end
|
||||
function bl.toobject(id)
|
||||
function bl.object(id)
|
||||
if type(id)=='table' and id._tsObjectId then
|
||||
return id
|
||||
elseif type(id)=='string' or type(id)=='number' then
|
||||
|
||||
Reference in New Issue
Block a user