-- Library: luacon -- Version: 0.2.2 -- Author: reyalp (at) gmail.com -- Description: -- interactive lua console in the etpro server for testing and development. -- -- coding usage: -- require('luacon') -- see luaconmod.lua for an example standalone module -- The namespace hack is suggested but not required. -- -- To run luacon in your module, simply invoke LuaCon:DoCommand as -- shown in the et_ConsoleCommand in luaconmod.lua -- If you want to process other server console commands, just check -- the return value. Remember 0 means unhandled and 0 is not false. -- -- You may wish to disable luacon in your code before you release your module -- or install it on a production server, otherwise anyone with rcon might be -- tempted to toy with its innards. -- -- in game usage: -- in the server console (or using rcon) -- lua -- you can change the verbosity and time settings with lua code, e.g. -- lua "LuaCon.verbose = 2 ; LuaCon.time = true" -- -- Beware that the ET console eats double quotes, and semicolons outside -- of double quotes. -- Always use single quotes for lua strings in your console commands. -- If you need to use semicolon (;) use double quotes around your entire -- lua command. Never use double quotes anywhere else in your lua command. -- -- Changelog: -- 0.2.2: -- fix some G_Printfs that snuck through -- -- 0.2.1: -- don't try to print execute time on compile errors -- -- 0.2: -- Split standalone module -- Catch and report compile errors -- Package all settings and functions into a single table -- Timing support -- : -- initial release -- table for settings and DoCommand function LuaCon = { ['verbose'] = 0, -- general verbosity ['time'] = false, -- print timing info ['version'] = '0.2.2', -- printf wrapper ['Printf'] = function(...) et.G_Print(string.format(unpack(arg))) end, ['DoCommand'] = function (self) -- if verbosity is turned all the way up, print out individual args -- in brackets so we can see what ET might be doing to our command line if self.verbose > 1 then self.Printf( "arc: [%s] args: ", et.trap_Argc(), et.trap_Argv(0) ) local i = 0 while i < et.trap_Argc() do self.Printf(" [%s]",et.trap_Argv(i)) i = i + 1 end self.Printf("\n"); end if et.trap_Argv(0) == "lua" then local s = et.ConcatArgs( 1 ) local estart, efinish, cstart, cfinish local f,status,err if self.verbose > 0 then self.Printf( 'lua: "%s"\n', s ) end cstart = et.trap_Milliseconds() f,err = loadstring(s) cfinish = et.trap_Milliseconds() if f then estart = et.trap_Milliseconds() status,err = pcall(f) efinish = et.trap_Milliseconds() if not status then self.Printf( 'pcall error [%s]\n', err ) end else self.Printf( 'loadstring error [%s]\n', err ) end if self.time then self.Printf("compile: %d ms execute:", cfinish - cstart) -- don't try to print execute time on errors if f then self.Printf(" %d ms", efinish - estart) else self.Printf("") end self.Printf("\n") end return 1 end return 0 end } return 1