forked from redo/BlockLua
initial
This commit is contained in:
40
src/lua-env.lua
Normal file
40
src/lua-env.lua
Normal 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')
|
||||
Reference in New Issue
Block a user