reepblue Posted July 21 Share Posted July 21 I've tried to make an extension that'll compile all lua code in the project, but the Command/Run File doesn't seem to work. The printed command line looks fine and returns true when finished. local extension = {} function extension:RunLuac(file) local luac = AppDir().."/Tools/luac.exe" local o = " -o " .. "\"" .. StripExt(file)..".luac\" " local f = "\"" .. file .. "\"" if FileType(luac) == 0 then Print("Error: Failed to locate luac!") return end Print(luac .. o .. f) --Command("cd " .. CurrentDir()) if RunFile("\"" .. luac .. "\"" .. o .. f ) ~= 0 then Print("Success!") end end function ExecuteDir(path) local dir = LoadDir(path) for _, file in ipairs(dir) do local filepath = path .. "/" .. file; local t = FileType(filepath) if t == 1 then if ExtractExt(file) == "lua" then extension:RunLuac(filepath) end elseif t == 2 then ExecuteDir(filepath) end end end function extension.hook(event, extension) if event.id == EVENT_WIDGETACTION then ExecuteDir(CurrentDir().."/Source") end end -------------------------------------------------------------------- -- Add menu item -------------------------------------------------------------------- local menu = program.menu:FindChild("Scripting", false) if menu ~= nil then local submenu = menu:FindChild("Utilities", false) if submenu == nil then submenu = CreateMenu("Utilities", menu) end extension.menuitem = CreateMenu("Compile Lua Scripts", submenu) ListenEvent(EVENT_WIDGETACTION, extension.menuitem, extension.hook, extension) end Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Josh Posted July 21 Share Posted July 21 I don't think you can pass command-line arguments with the RunFile() command. The Command() or CreateProcess() functions would probably be better. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
reepblue Posted July 21 Author Share Posted July 21 Maybe CreateProcess() is what I wanted. Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Josh Posted July 21 Share Posted July 21 Command() should also work fine, because it is just running a windows console command. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
reepblue Posted July 21 Author Share Posted July 21 25 minutes ago, Josh said: Command() should also work fine, because it is just running a windows console command. I tried that too as mentioned in the opening post but nothing seemed to happen. Tried CreateProcess and it's still not outputting the luac files. I'll probably have better luck using a batch file. It's possible that UAC is getting in the way. local extension = {} function extension:RunLuac(file) local luac = AppDir().."/Tools/luac.exe" local o = " -o " .. "\"" .. StripExt(file)..".luac\" " local f = "\"" .. file .. "\"" if FileType(luac) == 0 then Print("Error: Failed to locate luac!") return end Print(luac .. o .. f) --Command("cd " .. CurrentDir()) CreateProcess("\"" .. luac .."\" " .. o .. f) --local exitcode = proc:Wait() --Print("Process ended (" .. tostring(exitcode) .. ")") --if RunFile("\"" .. luac .. "\"" .. o .. f ) ~= 0 then -- Print("Success!") --end end function ExecuteDir(path) local dir = LoadDir(path) for _, file in ipairs(dir) do local filepath = path .. "/" .. file; local t = FileType(filepath) if t == 1 then if ExtractExt(file) == "lua" then extension:RunLuac(filepath) end elseif t == 2 then ExecuteDir(filepath) end end end function extension.hook(event, extension) if event.id == EVENT_WIDGETACTION then ExecuteDir(CurrentDir().."/Source") ExecuteDir(CurrentDir().."/Scripts") end end -------------------------------------------------------------------- -- Add menu item -------------------------------------------------------------------- local menu = program.menu:FindChild("Scripting", false) if menu ~= nil then local submenu = menu:FindChild("Utilities", false) if submenu == nil then submenu = CreateMenu("Utilities", menu) end extension.menuitem = CreateMenu("Compile Lua Scripts", submenu) ListenEvent(EVENT_WIDGETACTION, extension.menuitem, extension.hook, extension) end Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Josh Posted July 21 Share Posted July 21 With CreateProcess, you pass your arguments in a second function parameter. I tested with Command. If I print out the command string and paste it into a Windows console it works correctly, but if I run the string with Command(), which is just calling wsystem() under the hood, it seems to not like the space in the path: Quote 'C:\Projects\Ultra' is not recognized as an internal or external command, operable program or batch file. There are quotation marks around the path, so I am not sure why it doesn't work. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Josh Posted July 21 Share Posted July 21 Same problem here. I will try adding extra quotation marks in the command: https://stackoverflow.com/questions/9964865/c-system-not-working-when-there-are-spaces-in-two-different-parameters Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Josh Posted July 21 Share Posted July 21 This will work in the next build that goes up: function extension:RunLuac(file) local luac = AppDir().."/Tools/luac.exe" local o = " -o " .. "\"" .. StripExt(file)..".luac\" " local f = "\"" .. file .. "\"" if FileType(luac) == 0 then Print("Error: Failed to locate luac!") return end local command = "\"" .. luac .."\"" .. o .. f command = Replace(command, "/", "\\") Print(command) Command(command) end Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
reepblue Posted July 21 Author Share Posted July 21 Oh wow, I ended up finding a bug! Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Josh Posted July 21 Share Posted July 21 It works now. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
reepblue Posted August 14 Author Share Posted August 14 This works great, thank you! local extension = {} function extension:RunLuac(file) local luac = AppDir().."/Tools/luac.exe" local o = " -o " .. "\"" .. StripExt(file)..".luac\" " local f = "\"" .. file .. "\"" if FileType(luac) == 0 then Print("Error: Failed to locate luac!") return end local command = "\"" .. luac .."\"" .. o .. f command = Replace(command, "/", "\\") Print(command) Command(command) end function ExecuteDir(path) local dir = LoadDir(path) for _, file in ipairs(dir) do local filepath = path .. "/" .. file; local t = FileType(filepath) if t == 1 then if ExtractExt(file) == "lua" then extension:RunLuac(filepath) end elseif t == 2 then ExecuteDir(filepath) end end end function extension.hook(event, extension) if event.id == EVENT_WIDGETACTION then ExecuteDir(CurrentDir().."/Source") ExecuteDir(CurrentDir().."/Scripts") end end -------------------------------------------------------------------- -- Add menu item -------------------------------------------------------------------- local menu = program.menu:FindChild("Scripting", false) if menu ~= nil then local submenu = menu:FindChild("Utilities", false) if submenu == nil then submenu = CreateMenu("Utilities", menu) end extension.menuitem = CreateMenu("Compile Lua Scripts", submenu) ListenEvent(EVENT_WIDGETACTION, extension.menuitem, extension.hook, extension) end Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.