make :members() not return index, add -DBLLUA_ALLOWFFI, allow reading modules/lualib/, bug fixes
This commit is contained in:
@@ -107,13 +107,14 @@ end
|
||||
|
||||
-- Type conversion from TS to Lua
|
||||
local fromTsForceTypes = {
|
||||
['boolean'] = tsBool,
|
||||
['object'] = function(val) toTsObject(val) end, -- wrap because toTsObject not defined yet
|
||||
['boolean'] = function(val) return tsBool(val) end,
|
||||
['object'] = function(val) return toTsObject(val) end, -- wrap because toTsObject not defined yet
|
||||
['string'] = function(val) return val end,
|
||||
}
|
||||
local function forceValFromTs(val, typ)
|
||||
return fromTsForceTypes[typ](val) or
|
||||
error('valFromTs: invalid force type '..typ, 4)
|
||||
local func = fromTsForceTypes[typ]
|
||||
if not func then error('valFromTs: invalid force type \''..typ..'\'', 4) end
|
||||
return func(val)
|
||||
end
|
||||
local function vectorFromTs(val)
|
||||
local xS,yS,zS = val:match('^(%-?[0-9%.e]+) (%-?[0-9%.e]+) (%-?[0-9%.e]+)$')
|
||||
@@ -154,7 +155,8 @@ local function multinumericFromTs(val)
|
||||
end
|
||||
end
|
||||
bl._forceType = bl._forceType or {}
|
||||
local function valFromTs(val, name, name2) -- todo: ensure name and name2 are already lowercase
|
||||
-- todo: ensure name and name2 are already lowercase
|
||||
local function valFromTs(val, name, name2)
|
||||
if type(val)~='string' then
|
||||
error('valFromTs: expected string, got '..type(val), 3) end
|
||||
if name then
|
||||
@@ -362,17 +364,19 @@ local tsObjectMeta = {
|
||||
tsIsFunctionNs(rawget(t,'_tsNamespace'), name) or
|
||||
tsIsFunctionNs(rawget(t,'_tsName'), name)
|
||||
then
|
||||
return function(t, ...)
|
||||
local args = {...}
|
||||
local argsS = arglistToTs(args)
|
||||
return valFromTs(
|
||||
_bllua_ts.callobj(rawget(t,'_tsObjectId'), name, unpack(argsS)),
|
||||
rawget(t,'_tsName') and rawget(t,'_tsName')..'::'..name,
|
||||
rawget(t,'_tsNamespace')..'::'..name)
|
||||
return function(t2, ...)
|
||||
if t2==nil or type(t2)~='table' or not t2._tsObjectId then
|
||||
error('ts object method: be sure to use :func() not .func()', 2) end
|
||||
local argsS = arglistToTs({...})
|
||||
local res =
|
||||
_bllua_ts.callobj(t2._tsObjectId, name, unpack(argsS))
|
||||
return valFromTs(res,
|
||||
t2._tsName and t2._tsName..'::'..name,
|
||||
t2._tsNamespace..'::'..name)
|
||||
end
|
||||
else
|
||||
return valFromTs(
|
||||
_bllua_ts.getfield(rawget(t,'_tsObjectId'), name),
|
||||
local res = _bllua_ts.getfield(rawget(t,'_tsObjectId'), name)
|
||||
return valFromTs(res,
|
||||
rawget(t,'_tsName') and rawget(t,'_tsName')..'.'..name,
|
||||
rawget(t,'_tsNamespace')..'.'..name)
|
||||
end
|
||||
@@ -437,7 +441,8 @@ local tsObjectMeta = {
|
||||
local obj = toTsObject(_bllua_ts.callobj(t._tsObjectId,
|
||||
'getObject', tostring(idx)))
|
||||
idx = idx+1
|
||||
return idx-1, obj
|
||||
--return idx-1, obj
|
||||
return obj
|
||||
else
|
||||
return nil
|
||||
end
|
||||
@@ -559,9 +564,9 @@ local function tsNamespacedCallTfname(name)
|
||||
end
|
||||
local function tsCallGen(name)
|
||||
return function(...)
|
||||
local args = {...}
|
||||
local argsS = arglistToTs(args)
|
||||
return valFromTs(_bllua_ts.call(name, unpack(argsS)), name)
|
||||
local argsS = arglistToTs({...})
|
||||
local res = _bllua_ts.call(name, unpack(argsS))
|
||||
return valFromTs(res, name)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -587,14 +592,16 @@ local tsMeta = {
|
||||
if not rest:find('::') and tsIsFunctionNs(ns, rest) then
|
||||
return tsCallGen(tsNamespacedCallTfname(name))
|
||||
else
|
||||
return valFromTs(_bllua_ts.getvar(name), name)
|
||||
local res = _bllua_ts.getvar(name)
|
||||
return valFromTs(res, name)
|
||||
end
|
||||
elseif tsIsFunction(name) then
|
||||
return tsCallGen(name)
|
||||
elseif tsIsObject(name) then
|
||||
return toTsObject(name)
|
||||
else
|
||||
return valFromTs(_bllua_ts.getvar(name), name)
|
||||
local res = _bllua_ts.getvar(name)
|
||||
return valFromTs(res, name)
|
||||
end
|
||||
end
|
||||
end,
|
||||
@@ -613,10 +620,12 @@ function bl.call(func, ...)
|
||||
return _bllua_ts.call(func, unpack(argsS))
|
||||
end
|
||||
function bl.eval(code)
|
||||
return valFromTs(_bllua_ts.eval(code))
|
||||
local res = _bllua_ts.eval(code)
|
||||
return valFromTs(res)
|
||||
end
|
||||
function bl.exec(file)
|
||||
return valFromTs(_bllua_ts.call('exec', file))
|
||||
local res = _bllua_ts.call('exec', file)
|
||||
return valFromTs(res)
|
||||
end
|
||||
function bl.array(name, ...)
|
||||
local rest = {...}
|
||||
@@ -645,7 +654,6 @@ end
|
||||
-- Lua calling from TS
|
||||
local luaLookup
|
||||
luaLookup = function(tbl, name, set, val)
|
||||
print('lookup', tbl, name, set, val)
|
||||
if name:find('%.') then
|
||||
local first, rest = name:match('^([^%.:]+)%.(.+)$')
|
||||
if not isValidFuncName(first) then
|
||||
@@ -661,6 +669,8 @@ luaLookup = function(tbl, name, set, val)
|
||||
error('luacall: cannot have : or . after :', 3) end
|
||||
if not isValidFuncName(first) then
|
||||
error('luacall: invalid name \''..tostring(first)..'\'', 3) end
|
||||
if not isValidFuncName(rest) then
|
||||
error('luacall: invalid method name \''..tostring(first)..'\'', 3) end
|
||||
if not tbl[first] then
|
||||
error('luacall: no object named \''..rest..'\'', 3) end
|
||||
if not tbl[first][rest] then
|
||||
@@ -681,7 +691,7 @@ function _bllua_call(fname, ...)
|
||||
local args = arglistFromTs(fname:lower(), {...}) -- todo: separate lua from ts func names?
|
||||
local func = luaLookup(_G, fname)
|
||||
if not func then
|
||||
error('luacall: no global in lua named \''..name..'\'', 2) end
|
||||
error('luacall: no global in lua named \''..fname..'\'', 2) end
|
||||
local res = func(unpack(args))
|
||||
return valToTs(res)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user