forked from redo/BlockLua
46 lines
1.4 KiB
Lua
46 lines
1.4 KiB
Lua
-- 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
|
|
|
|
-- overridden in lua-env-safe.lua (executed if not BLLUA_UNSAFE)
|
|
_bllua_io_open = io.open
|
|
_bllua_requiresecure = require
|
|
|
|
print = _bllua_ts.echo
|
|
print(' Executed bllua-env.lua')
|