forked from pkulchenko/ZeroBranePackage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheris.lua
116 lines (103 loc) · 4.49 KB
/
eris.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
local function makeErisInterpreter( version, name, basename )
basename = basename or 'lua'
assert( basename:match( '^%l+$' ), 'Executable basename must be all lowercase' )
local capbasename = basename:sub( 1, 1 ):upper() .. basename:sub( 2 )
local function exePath(self, version)
local version = tostring(version or ""):gsub('%.','')
local mainpath = ide:GetRootPath()
local macExe = mainpath..([[bin/%s.app/Contents/MacOS/%s%s]]):format(basename, basename, version)
return (ide.config.path[basename..version]
or (ide.osname == "Windows" and mainpath..([[bin\%s%s.exe]]):format(basename, version))
or (ide.osname == "Unix" and mainpath..([[bin/linux/%s/%s%s]]):format(ide.osarch, basename, version))
or (wx.wxFileExists(macExe) and macExe or mainpath..([[bin/%s%s]]):format(basename, version))),
ide.config.path[basename..version] ~= nil
end
return {
name = ("%s%s"):format(capbasename, name or version or ""),
description = ("%s%s interpreter with debugger"):format(capbasename, name or version or ""),
api = {"baselib"},
luaversion = version or '5.1',
fexepath = exePath,
frun = function(self,wfilename,rundebug)
local exe, iscustom = self:fexepath(version or "")
local filepath = wfilename:GetFullPath()
do
-- 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)
local shortpath = winapi.short_path(filepath)
if shortpath == filepath then
ide:Print(
("Can't get short path for a Unicode file name '%s' to open the file.")
:format(filepath))
ide:Print(
("You can enable short names by using `fsutil 8dot3name set %s: 0` and recreate the file or directory.")
:format(wfilename:GetVolume()))
end
filepath = shortpath
end
end
if rundebug then
ide:GetDebugger():SetOptions({runstart = ide.config.debugger.runonstart == true})
-- update arg to point to the proper file
rundebug = ('if arg then arg[0] = [[%s]] end '):format(filepath)..rundebug
local tmpfile = wx.wxFileName()
tmpfile:AssignTempFileName(".")
filepath = tmpfile:GetFullPath()
local f = io.open(filepath, "w")
if not f then
ide:Print("Can't open temporary file '"..filepath.."' for writing.")
return
end
f:write(rundebug)
f:close()
end
local params = self:GetCommandLineArg("lua")
local code = ([[-e "io.stdout:setvbuf('no')" "%s"]]):format(filepath)
local cmd = '"'..exe..'" '..code..(params and " "..params or "")
-- modify CPATH to work with other Lua versions
local envname = "LUA_CPATH"
if version then
local env = "LUA_CPATH_"..string.gsub(version, '%.', '_')
if os.getenv(env) then envname = env end
end
local cpath = os.getenv(envname)
if rundebug and cpath and not iscustom then
-- prepend osclibs as the libraries may be needed for debugging,
-- but only if no path.lua is set as it may conflict with system libs
wx.wxSetEnv(envname, ide.osclibs..';'..cpath)
end
if version and cpath then
local cpath = os.getenv(envname)
local clibs = string.format('/clibs%s/', version):gsub('%.','')
if not cpath:find(clibs, 1, true) then cpath = cpath:gsub('/clibs/', clibs) end
wx.wxSetEnv(envname, cpath)
end
-- CommandLineRun(cmd,wdir,tooutput,nohide,stringcallback,uid,endcallback)
local pid = CommandLineRun(cmd,self:fworkdir(wfilename),true,false,nil,nil,
function() if rundebug then wx.wxRemoveFile(filepath) end end)
if (rundebug or version) and cpath then wx.wxSetEnv(envname, cpath) end
return pid
end,
hasdebugger = true,
scratchextloop = false,
unhideanywindow = true,
takeparameters = true,
}
end
return {
name = "Eris",
description = "Implements integration with the Lua + Eris interpreter (5.3).",
author = "raingloom",
version = 0.11,
onRegister = function()
ide:AddInterpreter( 'eris53', makeErisInterpreter(5.3, '5.3', 'eris'))
end,
onUnRegister = function()
ide:RemoveInterpreter( 'eris53' )
end,
}