diff --git a/.gitignore b/.gitignore index 9ea0f13..977d061 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ -.* !.gitignore +.* +build/ diff --git a/BlockLua.dll b/BlockLua.dll deleted file mode 100644 index 962b4c3..0000000 Binary files a/BlockLua.dll and /dev/null differ diff --git a/compile.bat b/compile.bat index d812f9a..e514da8 100644 --- a/compile.bat +++ b/compile.bat @@ -5,12 +5,13 @@ set buildargs=-Wall -Werror -m32 -shared -Isrc -Iinc/tsfuncs -Iinc/lua -lpsapi - echo on -g++ src/bllua4.cpp %buildargs% -o BlockLua.dll -@rem g++ -DBLLUA_UNSAFE src/bllua4.cpp %buildargs% -o BlockLua-Unsafe.dll +set outdir=build +if not exist %outdir% mkdir %outdir% + +g++ src/bllua4.cpp %buildargs% -o %outdir%\BlockLua.dll +@rem g++ -DBLLUA_UNSAFE src/bllua4.cpp %buildargs% -o %outdir%\BlockLua-Unsafe.dll @echo off -rem objdump -d BlockLua.dll > BlockLua.dll.dump.txt -rem objdump -d BlockLua-Unsafe.dll > BlockLua-Unsafe.dll.dump.txt - -pause +rem objdump -d %outdir%\BlockLua.dll > %outdir%\BlockLua.dll.dump.txt +rem objdump -d %outdir%\BlockLua-Unsafe.dll > %outdir%\BlockLua-Unsafe.dll.dump.txt diff --git a/compile.sh b/compile.sh new file mode 100644 index 0000000..c29cfda --- /dev/null +++ b/compile.sh @@ -0,0 +1,29 @@ +#!/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++" + +outdir="build" +mkdir -p "$outdir" + +set -x +/mingw32/bin/g++ src/bllua4.cpp $buildargs -o "$outdir"/BlockLua.dll && /mingw32/bin/g++ -DBLLUA_UNSAFE src/bllua4.cpp $buildargs -o "$outdir"/BlockLua-Unsafe.dll +set +x + +# objdump -d "$outdir"/BlockLua.dll > "$outdir"/BlockLua.dll.dump.txt +# objdump -d "$outdir"/BlockLua-Unsafe.dll > "$outdir"/BlockLua-Unsafe.dll.dump.txt diff --git a/src/util/libts-lua.lua b/src/util/libts-lua.lua index 96ef5fc..5628c2e 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) + local fi, err, fn2 = io.open(fn, 'r', 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)