Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- WTF: this is lua script launcher for shortcuts or debugging
- -- Usage: run in shell:
- -- path/to/lua/executable /path/to/this/launcher.lua /path/to/script.lua
- -- Example: notepad++ shortcut looks like this (alt + f1):
- -- <Command name="Lua" Ctrl="no" Alt="yes" Shift="no" Key="112">
- -- luajit c:\lua\launcher.lua $(FULL_CURRENT_PATH)
- -- </Command>
- -- Features:
- -- 1. Console window doesn't disappear, we can debug script after launch
- -- 2. Package paths configured for [/path/to/script.lua], run it like project
- -- 3. Sweet traceback!
- -- Tricks: write 'cont' on 'lua_debug' mode
- -- Written by snus (C) for internal corporate usage, if you see it - go to jail now.
- local path_sep = package.config:sub(1, 1)
- local shared_ext = path_sep == '\\' and 'dll' or 'so'
- -- shift args back
- for i = 0, #arg do
- arg[i] = arg[i + 1]
- end
- -- Init path
- local scrPath = arg[0] or os.exit()
- scrPath = scrPath:gsub('[\\/]', '/')
- local __path, __name = scrPath:match'^(.*)/(.-).lua$'
- local __name_ext = __name .. '.lua'
- package.path = __path..'/?/init.lua;' .. package.path
- package.path = __path..'/?.lua;' .. package.path
- package.cpath = __path..'/?/core.' .. shared_ext .. ';' .. package.cpath
- package.cpath = __path..'/?.' .. shared_ext .. ';' .. package.cpath
- package.path = package.path:gsub('[\\/]', path_sep)
- package.cpath = package.cpath:gsub('[\\/]', path_sep)
- local function errorprinter(msg, layer)
- -- if it's nil or something
- msg = tostring(msg)
- local trace = debug.traceback(msg, 1 + (layer or 1))
- trace = trace:gsub('%[string "' .. __name_ext .. '"%]', __name_ext)
- -- cut four last lines of traceback
- local lines = ('\n[^\n]+'):rep(4) .. '$'
- trace = trace:gsub(lines, "")
- print("Error: " .. trace)
- end
- xpcall(function()
- local file = io.open(scrPath)
- local code = file:read('*a'); file:close()
- local chunk, err = loadstring(code, __name_ext)
- if not chunk then error(err, 2) end
- chunk()
- end,
- errorprinter
- )
- -- term window is not closed at end of task
- debug.debug()
Add Comment
Please, Sign In to add comment