improve readme, improve std lib
This commit is contained in:
@@ -536,7 +536,7 @@ end
|
||||
function bl.exec(file)
|
||||
return valFromTs(_bllua_ts.call('exec', file))
|
||||
end
|
||||
function bl.tobool(val)
|
||||
function bl.boolean(val)
|
||||
return val~=nil and
|
||||
val~=false and
|
||||
--val~='' and
|
||||
@@ -734,6 +734,9 @@ function bl.hook(pkg, name, time, func)
|
||||
updateHook(pkg, name, bl._hooks[pkg][name])
|
||||
activatePackage(pkg)
|
||||
end
|
||||
local function tableEmpty(t)
|
||||
return next(t)~=nil
|
||||
end
|
||||
function bl.unhook(pkg, name, time)
|
||||
if not isValidFuncName(pkg) then
|
||||
error('bl.unhook: argument #1: invalid package name \''..tostring(pkg)..'\'', 2) end
|
||||
@@ -766,7 +769,7 @@ function bl.unhook(pkg, name, time)
|
||||
if time~='before' and time~='after' then
|
||||
error('bl.unhook: argument #3: time must be nil, \'before\', or \'after\'', 2) end
|
||||
bl._hooks[pkg][name][time] = nil
|
||||
if table.empty(bl._hooks[pkg][name]) and table.empty(bl._hooks[pkg]) then
|
||||
if tableEmpty(bl._hooks[pkg][name]) and tableEmpty(bl._hooks[pkg]) then
|
||||
bl._hooks[pkg] = nil
|
||||
deactivatePackage(pkg)
|
||||
updateHook(pkg, name, {})
|
||||
@@ -871,10 +874,15 @@ function bl.radiusSearch(pos, radius, mask)
|
||||
end
|
||||
|
||||
-- Print/Talk/Echo
|
||||
local maxTsArgLen = 8192
|
||||
local function valsToString(vals)
|
||||
local strs = {}
|
||||
for i,v in ipairs(vals) do
|
||||
strs[i] = table.tostring(v)
|
||||
local tstr = table.tostring(v)
|
||||
if #tstr>maxTsArgLen then
|
||||
tstr = tostring(v)
|
||||
end
|
||||
strs[i] = tstr
|
||||
end
|
||||
return table.concat(strs, ' ')
|
||||
end
|
||||
@@ -889,11 +897,12 @@ bl.talk = function(...)
|
||||
_bllua_ts.call('talk', str)
|
||||
end
|
||||
|
||||
-- bl.new and bl.datablock
|
||||
local function createTsObj(keyword, class, name, inherit, props)
|
||||
local propsT = {}
|
||||
for k,v in pairs(props) do
|
||||
if not isValidFuncName(k) then
|
||||
error('bl.new/datablock: invalid property name \''..k..'\'') end
|
||||
error('bl.new/bl.datablock: invalid property name \''..k..'\'') end
|
||||
table.insert(propsT, k..'="'..valToTs(v)..'";')
|
||||
end
|
||||
|
||||
@@ -903,7 +912,7 @@ local function createTsObj(keyword, class, name, inherit, props)
|
||||
table.concat(propsT)..'};')
|
||||
local obj = toTsObject(objS)
|
||||
if not obj then
|
||||
error('bl.new/datablock: failed to create object', 3) end
|
||||
error('bl.new/bl.datablock: failed to create object', 3) end
|
||||
|
||||
return obj
|
||||
end
|
||||
@@ -926,7 +935,7 @@ local function parseTsDecl(decl)
|
||||
isValidFuncName(class) and
|
||||
(name==nil or isValidFuncName(name)) and
|
||||
(inherit==nil or isValidFuncName(inherit)) ) then
|
||||
error('bl.new/datablock: invalid decl \''..decl..'\'\n'..
|
||||
error('bl.new/bl.datablock: invalid decl \''..decl..'\'\n'..
|
||||
'must be of the format: \'className\', \'className name\', '..
|
||||
'\'className :inherit\', or \'className name:inherit\'', 3) end
|
||||
return class, name, inherit
|
||||
@@ -937,6 +946,7 @@ function bl.new(decl, props)
|
||||
end
|
||||
function bl.datablock(decl, props)
|
||||
local class, name, inherit = parseTsDecl(decl)
|
||||
if not name then error('bl.datablock: must specify a name', 2) end
|
||||
return createTsObj('datablock', class, name, inherit, props)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user