Skip to content

Instantly share code, notes, and snippets.

@drahosp
Created October 31, 2013 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drahosp/7250759 to your computer and use it in GitHub Desktop.
Save drahosp/7250759 to your computer and use it in GitHub Desktop.
LuaDist interpreter for ZBS 0.39. Unsets LUA_CPATH and LUA_PATH.
local exe
local function exePath()
local defaultPath = ide.config.path.luadist or "C:\\LuaDist\\bin\\"
return MergeFullPath(defaultPath, 'lua.exe')
end
return {
name = "LuaDist",
description = "LuaDist interpreter",
api = {"baselib"},
frun = function(self,wfilename,rundebug)
exe = exe or exePath()
local filepath = wfilename:GetFullPath()
local script
if rundebug then
DebuggerAttachDefault({basedir = self:fworkdir(wfilename),
runstart = ide.config.debugger.runonstart == true})
script = rundebug
else
-- if running on Windows and can't open the file, this may mean that
-- the file path includes unicode characters that need special handling
local fh = io.open(filepath, "r")
if fh then fh:close() end
if ide.osname == 'Windows' and pcall(require, "winapi")
and wfilename:FileExists() and not fh then
winapi.set_encoding(winapi.CP_UTF8)
filepath = winapi.short_path(filepath)
end
script = ('dofile [[%s]]'):format(filepath)
end
local code = ([[xpcall(function() io.stdout:setvbuf('no'); %s end,function(err) print(debug.traceback(err)) end)]]):format(script)
local cmd = '"'..exe..'" -e "'..code..'"'
-- unset any LUA_CPATH and LUA_PATH settings
local _, lua_cpath = wx.wxGetEnv("LUA_CPATH")
local _, lua_path = wx.wxGetEnv("LUA_PATH")
wx.wxSetEnv("LUA_CPATH", "" )
wx.wxSetEnv("LUA_PATH", "" )
-- CommandLineRun(cmd,wdir,tooutput,nohide,stringcallback,uid,endcallback)
local pid = CommandLineRun(cmd,self:fworkdir(wfilename),true,false,nil,nil,
function() ide.debugger.pid = nil end)
-- restore LUA_CPATH and LUA_PATH settings
wx.wxSetEnv("LUA_PATH", lua_path)
wx.wxSetEnv("LUA_CPATH", lua_cpath)
return pid
end,
fprojdir = function(self,wfilename)
return wfilename:GetPath(wx.wxPATH_GET_VOLUME)
end,
fworkdir = function (self,wfilename)
return wfilename:GetPath(wx.wxPATH_GET_VOLUME)
end,
hasdebugger = true,
fattachdebug = function(self) DebuggerAttachDefault() end,
scratchextloop = false,
unhideanywindow = true,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment