1
0
forked from redo/BlockLua
This commit is contained in:
Redo
2025-10-01 16:26:18 -07:00
commit 36ba54b248
43 changed files with 9810 additions and 0 deletions

40
src/lua-env.lua Normal file
View File

@@ -0,0 +1,40 @@
-- Set up the Lua environment
-- Point old require to modules/lua in game directory
package.path = 'modules\\lualib\\?.lua;modules\\lualib\\?\\init.lua;'
package.cpath = 'modules\\lualib\\?.dll;'
-- Set up table of unload/cleanup callbacks
_bllua_on_unload = {}
-- Utility for getting the current filename
function debug.getfilename(level)
if type(level) == 'number' then level = level+1 end
local info = debug.getinfo(level)
if not info then return nil end
local filename = info.source:match('^%-%-%[%[([^%]]+)%]%]')
return filename
end
-- Called when pcall fails on a ts->lua call, used to print detailed error info
function _bllua_on_error(err)
err = err:match(': (.+)$') or err
local tracelines = {err}
local level = 2
while true do
local info = debug.getinfo(level)
if not info then break end
local filename = debug.getfilename(level) or info.short_src
local funcname = info.name
if funcname=='dofile' then break end
table.insert(tracelines, string.format('%s:%s in function \'%s\'',
filename,
info.currentline==-1 and '' or info.currentline..':',
funcname
))
level = level+1
end
return table.concat(tracelines, '\n')
end
_bllua_ts.echo(' Executed bllua-env.lua')