diff --git a/BlockLua-Unsafe.dll b/BlockLua-Unsafe.dll new file mode 100644 index 0000000..3eb7dfe Binary files /dev/null and b/BlockLua-Unsafe.dll differ diff --git a/BlockLua.dll b/BlockLua.dll index 962b4c3..f6ff56d 100644 Binary files a/BlockLua.dll and b/BlockLua.dll differ diff --git a/compile.bat b/compile.bat index d812f9a..edee990 100644 --- a/compile.bat +++ b/compile.bat @@ -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 diff --git a/compile.sh b/compile.sh new file mode 100644 index 0000000..270ecf8 --- /dev/null +++ b/compile.sh @@ -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 diff --git a/src/util/libts-lua.lua b/src/util/libts-lua.lua index 96ef5fc..839191f 100644 --- a/src/util/libts-lua.lua +++ b/src/util/libts-lua.lua @@ -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)