require "Gelo" require "RudraScript" RudraRunner = {} RudraRunner.default_rudradir = ProgDir..'Scripts\\RudraScript\\' function RudraRunner:runscript(ext) local tabURL = tab.url local tabSource = tab.source if extbar.getval('button[name="clearlog"]') == 'True' then tab:clearlog() end Rudra.Set_CustomLibName('Sandcat') Rudra.Redirect_IO(true) Rudra.Import_Globals(false) script = extbar.getval('plaintext[name="script"]') extbar.setattrib('button[name="run"]','disabled','True') tab.statusbartext = 'Executing script...' if ext == 'js' then javascript(script) end if ext == 'pas' then pascalscript(script) end if ext == 'rem.pas' then rempascal(script) end if ext == 'pl' then perl(script) end if ext == 'php' then php(script) end if ext == 'py' then python(script) end if ext == 'rb' then ruby(script) end if ext == 'vbs' then vbscript(script) end extbar.setattrib('button[name="run"]','disabled','') tab.statusbartext = 'Done.' Rudra.Import_Globals(true) end function RudraRunner:openlua() extbar.setattrib('button[name="run"]','disabled','') local f = extbar.getval('select[name="scriptlist"]') local fcontents = '' if file_exists(self.default_rudradir..f) then fcontents = file_gettostr(self.default_rudradir..f) end extbar.setval('plaintext[name="script"]',fcontents) end function RudraRunner:get_scriptlist(ext) local p = GStrListParser:new() local flist = GStrList:new() local l = file_getdirfiles(self.default_rudradir..'*.'..ext) p:loadfromstr(l) while p:parsing() do flist:add('') end local result = flist.text flist:release() p:release() return result end function RudraRunner:loadscript(package,script) local code = browser.readfile(package,script) extbar.setval('plaintext[name="script"]',code) end function RudraRunner:vieweditor(lang_name,lang_ext,script,scbxname) local defaultscript = [[]] local example_menuitems = browser.readfile('Syhunt.scx','Examples/Menu_'..lang_name..'.html') local html = [[
</plaintext> </td> <td style="width:3px;"></td> <td style="width:40%;" valign="top"> External Scripts: <font color="gray">(Place your .]]..lang_ext..[[ scripts in <b>]]..ProgDir..[[Scripts\RudraScript\</b>)</font> <select .file-list name="scriptlist" size="5" style="width:100%;" onchange="RudraRunner:openlua()"> ]] local html_end = [[ </select><br><br> Available Variables:<br> <b>tabURL</b> = contains the tab URL<br> <b>tabSource</b> = contains the tab source<br><br> Notes:<br> Print functions will print the text to the Log tab <a id="button1" href="#">[?]</a><br> Any errors will be logged in the Error Console. </td> </tr></table> <button name="run" onclick="RudraRunner:runscript(']]..lang_ext..[[')">Execute ]]..lang_name..[[ <img src="Syhunt.scx#Images\icon_lang_]]..string.lower(lang_name)..[[.png" style="height:10px;width:10px;"></button> <button type="selector" menu="#example-items">Examples</button> &nbsp;&nbsp;<button type="checkbox" name="clearlog" checked>Clear log before execution</button> <div class="lightbox" id="dialog1"> <form class="dialog" style="width:*;height:*"> <div class="inner"> <div class="header"><caption>Help - Printing Text</caption></div> <div class="body"> From JavaScript, Pascal, Python, Ruby & VBScript:<br> Sandcat.Write() and Sandcat.WriteLn()<br> From Python, you can also use print()<br> From Ruby, you can also use puts()<br><br> From Perl: $Sandcat->Write() and $Sandcat->WriteLn()<br> From PHP: sandcat_write(), sandcat_writeln() or echo() </div> <div class="buttons"> <input type="button" id="ok" value="OK"> </div> </div> </form> </div> ]] if str_beginswith(tab.url,'http') then if script ~= nil then defaultscript = browser.readfile(scbxname,script) end extbar.load(html..self:get_scriptlist(lang_ext)..html_end) extbar.setval('plaintext[name="script"]',defaultscript) else app.showmessage('No URL loaded.') end end