lua interpreter upset by isnumber possibly returning nil. Check if nil to reduce warnings + safety! #3

Closed
Auios wants to merge 10 commits from Auios:_bllua_schedule_callback-checks-id-is-nil-first into master
5 changed files with 38 additions and 3 deletions

BIN
BlockLua-Unsafe.dll Normal file

Binary file not shown.

Binary file not shown.

View File

@@ -12,5 +12,3 @@ g++ src/bllua4.cpp %buildargs% -o BlockLua.dll
rem objdump -d BlockLua.dll > BlockLua.dll.dump.txt
rem objdump -d BlockLua-Unsafe.dll > BlockLua-Unsafe.dll.dump.txt
pause

26
compile.sh Normal file
View 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

View File

@@ -7,7 +7,11 @@ ts = _bllua_ts
-- Provide limited OS functions
os = os or {}
---@diagnostic disable-next-line: duplicate-set-field
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
-- Virtual file class, emulating a file object as returned by io.open
@@ -106,9 +110,10 @@ local function io_open_absolute(fn, mode)
end
io = io or {}
---@diagnostic disable-next-line: duplicate-set-field
function io.open(fn, mode, errn)
errn = errn or 1
-- try to open the file with relative path, otherwise use absolute path
local curfn = debug.getfilename(errn + 1) or _bllua_ts.getvar('Con::File')
if curfn == '' then curfn = nil end
@@ -126,13 +131,19 @@ function io.open(fn, mode, errn)
return fi, err, fn
end
end
---@diagnostic disable-next-line: duplicate-set-field
function io.lines(fn)
local fi, err, fn2 = io.open(fn, nil, 2)
if not fi then error('Error opening file \''..fn2..'\': '..err, 2) end
return fi:lines()
end
---@diagnostic disable-next-line: duplicate-set-field
function io.type(f)
---@diagnostic disable-next-line: undefined-field
if type(f)=='table' and f._is_file then
---@diagnostic disable-next-line: undefined-field
return f._is_open and 'file' or 'closed file'
else
return _bllua_io_type(f)