use table.empty instead of table.isempty. + added compile.sh
#1
Binary file not shown.
BIN
BlockLua.dll
BIN
BlockLua.dll
Binary file not shown.
@@ -9,5 +9,3 @@ g++ src/bllua4.cpp %buildargs% -o BlockLua.dll && g++ -DBLLUA_UNSAFE src/bllua4.
|
|||||||
|
|
||||||
rem objdump -d BlockLua.dll > BlockLua.dll.dump.txt
|
rem objdump -d BlockLua.dll > BlockLua.dll.dump.txt
|
||||||
rem objdump -d BlockLua-Unsafe.dll > BlockLua-Unsafe.dll.dump.txt
|
rem objdump -d BlockLua-Unsafe.dll > BlockLua-Unsafe.dll.dump.txt
|
||||||
|
|
||||||
pause
|
|
||||||
|
|||||||
26
compile.sh
Normal file
26
compile.sh
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#
|
||||||
|
# BlockLua build script for MSYS2/MinGW32
|
||||||
|
#
|
||||||
|
# Usage:
|
||||||
|
# 1. Open the MSYS2 MinGW32 shell.
|
||||||
|
# 2. Install the required compiler with:
|
||||||
|
# pacman -S mingw-w64-i686-gcc
|
||||||
|
# 3. Run this script:
|
||||||
|
# ./compile.sh
|
||||||
|
#
|
||||||
|
# If your MSYS2 installation is not on C:, adjust the g++ path below as needed.
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
cd "$(dirname "$0")"
|
||||||
|
|
||||||
|
buildargs="-Wall -Werror -m32 -shared -Isrc -Iinc/tsfuncs -Iinc/lua -lpsapi -L. -llua5.1 -static-libgcc -static-libstdc++"
|
||||||
|
|
||||||
|
set -x
|
||||||
|
/mingw32/bin/g++ src/bllua4.cpp $buildargs -o BlockLua.dll && /mingw32/bin/g++ -DBLLUA_UNSAFE src/bllua4.cpp $buildargs -o BlockLua-Unsafe.dll
|
||||||
|
set +x
|
||||||
|
|
||||||
|
# objdump -d BlockLua.dll > BlockLua.dll.dump.txt
|
||||||
|
# objdump -d BlockLua-Unsafe.dll > BlockLua-Unsafe.dll.dump.txt
|
||||||
@@ -38,7 +38,7 @@ end
|
|||||||
-- chains a bunch of filters together
|
-- chains a bunch of filters together
|
||||||
-- (thanks to Wim Couwenberg)
|
-- (thanks to Wim Couwenberg)
|
||||||
function filter.chain(...)
|
function filter.chain(...)
|
||||||
local n = table.getn(arg)
|
local n = #arg
|
||||||
local top, index = 1, 1
|
local top, index = 1, 1
|
||||||
local retry = ""
|
local retry = ""
|
||||||
return function(chunk)
|
return function(chunk)
|
||||||
|
|||||||
@@ -254,7 +254,7 @@ function parse_path(path)
|
|||||||
path = path or ""
|
path = path or ""
|
||||||
--path = string.gsub(path, "%s", "")
|
--path = string.gsub(path, "%s", "")
|
||||||
string.gsub(path, "([^/]+)", function (s) table.insert(parsed, s) end)
|
string.gsub(path, "([^/]+)", function (s) table.insert(parsed, s) end)
|
||||||
for i = 1, table.getn(parsed) do
|
for i = 1, #parsed do
|
||||||
parsed[i] = unescape(parsed[i])
|
parsed[i] = unescape(parsed[i])
|
||||||
end
|
end
|
||||||
if string.sub(path, 1, 1) == "/" then parsed.is_absolute = 1 end
|
if string.sub(path, 1, 1) == "/" then parsed.is_absolute = 1 end
|
||||||
@@ -272,7 +272,7 @@ end
|
|||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
function build_path(parsed, unsafe)
|
function build_path(parsed, unsafe)
|
||||||
local path = ""
|
local path = ""
|
||||||
local n = table.getn(parsed)
|
local n = #parsed
|
||||||
if unsafe then
|
if unsafe then
|
||||||
for i = 1, n-1 do
|
for i = 1, n-1 do
|
||||||
path = path .. parsed[i]
|
path = path .. parsed[i]
|
||||||
|
|||||||
@@ -446,7 +446,7 @@ local tsMeta = {
|
|||||||
elseif name:find('::') then
|
elseif name:find('::') then
|
||||||
local ns, rest = name:match('^([^:]+)::(.+)$')
|
local ns, rest = name:match('^([^:]+)::(.+)$')
|
||||||
if not ns then error('ts index: invalid name \''..name..'\'', 2) end
|
if not ns then error('ts index: invalid name \''..name..'\'', 2) end
|
||||||
if not rest:find('::') and tsIsFunction(ns, rest) then
|
if not rest:find('::') and tsIsFunction(ns, rest) then -- tsIsFunction is only defined with one argument
|
||||||
error('ts index: can\'t call a namespaced function from lua', 2)
|
error('ts index: can\'t call a namespaced function from lua', 2)
|
||||||
else
|
else
|
||||||
return valFromTs(_bllua_ts.getvar(name), name)
|
return valFromTs(_bllua_ts.getvar(name), name)
|
||||||
@@ -536,6 +536,9 @@ function bl.schedule(time, cb, ...)
|
|||||||
end
|
end
|
||||||
function _bllua_schedule_callback(id)
|
function _bllua_schedule_callback(id)
|
||||||
id = tonumber(id)
|
id = tonumber(id)
|
||||||
|
if id == nil then
|
||||||
|
error('_ts_schedule_callback: invalid id')
|
||||||
|
end
|
||||||
local sch = bl._scheduleTable[id]
|
local sch = bl._scheduleTable[id]
|
||||||
if not sch then error('_ts_schedule_callback: no schedule with id '..id) end
|
if not sch then error('_ts_schedule_callback: no schedule with id '..id) end
|
||||||
bl._scheduleTable[id] = nil
|
bl._scheduleTable[id] = nil
|
||||||
@@ -653,7 +656,7 @@ function bl.unhook(pkg, name, time)
|
|||||||
if bl._hooks[pkg][name] then
|
if bl._hooks[pkg][name] then
|
||||||
if not time then
|
if not time then
|
||||||
bl._hooks[pkg][name] = nil
|
bl._hooks[pkg][name] = nil
|
||||||
if table.isempty(bl._hooks[pkg]) then
|
if table.empty(bl._hooks[pkg]) then
|
||||||
bl._hooks[pkg] = nil
|
bl._hooks[pkg] = nil
|
||||||
deactivatePackage(pkg)
|
deactivatePackage(pkg)
|
||||||
end
|
end
|
||||||
@@ -663,7 +666,7 @@ function bl.unhook(pkg, name, time)
|
|||||||
error('bl.unhook: argument #3: time must be nil or one of '..
|
error('bl.unhook: argument #3: time must be nil or one of '..
|
||||||
'\'before\' \'after\' \'override\'', 2) end
|
'\'before\' \'after\' \'override\'', 2) end
|
||||||
bl._hooks[pkg][name][time] = nil
|
bl._hooks[pkg][name][time] = nil
|
||||||
if table.isempty(bl._hooks[pkg][name]) and table.empty(bl._hooks[pkg]) then
|
if table.empty(bl._hooks[pkg][name]) and table.empty(bl._hooks[pkg]) then
|
||||||
bl._hooks[pkg] = nil
|
bl._hooks[pkg] = nil
|
||||||
deactivatePackage(pkg)
|
deactivatePackage(pkg)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -7,7 +7,11 @@ ts = _bllua_ts
|
|||||||
|
|
||||||
-- Provide limited OS functions
|
-- Provide limited OS functions
|
||||||
os = os or {}
|
os = os or {}
|
||||||
|
|
||||||
|
---@diagnostic disable-next-line: duplicate-set-field
|
||||||
function os.time() return math.floor(tonumber(_bllua_ts.call('getSimTime'))/1000) end
|
function os.time() return math.floor(tonumber(_bllua_ts.call('getSimTime'))/1000) end
|
||||||
|
|
||||||
|
---@diagnostic disable-next-line: duplicate-set-field
|
||||||
function os.clock() return tonumber(_bllua_ts.call('getSimTime'))/1000 end
|
function os.clock() return tonumber(_bllua_ts.call('getSimTime'))/1000 end
|
||||||
|
|
||||||
-- Virtual file class, emulating a file object as returned by io.open
|
-- Virtual file class, emulating a file object as returned by io.open
|
||||||
@@ -106,9 +110,10 @@ local function io_open_absolute(fn, mode)
|
|||||||
end
|
end
|
||||||
|
|
||||||
io = io or {}
|
io = io or {}
|
||||||
|
---@diagnostic disable-next-line: duplicate-set-field
|
||||||
function io.open(fn, mode, errn)
|
function io.open(fn, mode, errn)
|
||||||
errn = errn or 1
|
errn = errn or 1
|
||||||
|
|
||||||
-- try to open the file with relative path, otherwise use absolute path
|
-- try to open the file with relative path, otherwise use absolute path
|
||||||
local curfn = debug.getfilename(errn + 1) or _bllua_ts.getvar('Con::File')
|
local curfn = debug.getfilename(errn + 1) or _bllua_ts.getvar('Con::File')
|
||||||
if curfn == '' then curfn = nil end
|
if curfn == '' then curfn = nil end
|
||||||
@@ -116,23 +121,29 @@ function io.open(fn, mode, errn)
|
|||||||
local relfn = curfn and fn:find('^%./') and
|
local relfn = curfn and fn:find('^%./') and
|
||||||
curfn:gsub('[^/]+$', '')..fn:gsub('^%./', '')
|
curfn:gsub('[^/]+$', '')..fn:gsub('^%./', '')
|
||||||
if relfn then
|
if relfn then
|
||||||
local fi, err = io_open_absolute(relfn, mode, errn+1)
|
local fi, err = io_open_absolute(relfn, mode, errn+1) -- defined with 2 args? function io_open_absolute(fn, mode)
|
||||||
return fi, err, relfn
|
return fi, err, relfn
|
||||||
else
|
else
|
||||||
return nil, 'Invalid path', fn
|
return nil, 'Invalid path', fn
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local fi, err = io_open_absolute(fn, mode, errn+1)
|
local fi, err = io_open_absolute(fn, mode, errn+1) -- defined with 2 args but passed 3 in.
|
||||||
return fi, err, fn
|
return fi, err, fn
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@diagnostic disable-next-line: duplicate-set-field
|
||||||
function io.lines(fn)
|
function io.lines(fn)
|
||||||
local fi, err, fn2 = io.open(fn, nil, 2)
|
local fi, err, fn2 = io.open(fn, nil, 2)
|
||||||
if not fi then error('Error opening file \''..fn2..'\': '..err, 2) end
|
if not fi then error('Error opening file \''..fn2..'\': '..err, 2) end
|
||||||
return fi:lines()
|
return fi:lines()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@diagnostic disable-next-line: duplicate-set-field
|
||||||
function io.type(f)
|
function io.type(f)
|
||||||
|
---@diagnostic disable-next-line: undefined-field
|
||||||
if type(f)=='table' and f._is_file then
|
if type(f)=='table' and f._is_file then
|
||||||
|
---@diagnostic disable-next-line: undefined-field
|
||||||
return f._is_open and 'file' or 'closed file'
|
return f._is_open and 'file' or 'closed file'
|
||||||
else
|
else
|
||||||
return _bllua_io_type(f)
|
return _bllua_io_type(f)
|
||||||
|
|||||||
Reference in New Issue
Block a user