Created
November 21, 2015 04:32
-
-
Save ar1a/9a7222a20d28d5df9715 to your computer and use it in GitHub Desktop.
lua console v1 by aria
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--thanks metaman for some stuff | |
os.execute("cls") | |
print([[ __ ________ _ _____ ____ __ __ ______ _____ _____ | |
\ \ / / ____| | / ____/ __ \| \/ | ____| /\ | __ \|_ _| /\ | |
\ \ /\ / /| |__ | | | | | | | | \ / | |__ / \ | |__) | | | / \ | |
\ \/ \/ / | __| | | | | | | | | |\/| | __| / /\ \ | _ / | | / /\ \ | |
\ /\ / | |____| |___| |___| |__| | | | | |____ / ____ \| | \ \ _| |_ / ____ \ | |
\/ \/ |______|______\_____\____/|_| |_|______| /_/ \_\_| \_\_____/_/ \_\ | |
]]) | |
print('Type help for commands.\nType exit to quit.\nLua code is accepted.') | |
commands = {} | |
commands.help = function() | |
print('---------HELP DIALOG---------') | |
for command, executor in pairs(commands) do | |
print(command) | |
end | |
end | |
commands.cmd = function() | |
os.execute("start") | |
end | |
local env = {} | |
commands.restart = function() | |
env = table.Copy(_G) --restores the lua environment | |
commands.clear() | |
end | |
function istable(t) return type(t) == 'table' end | |
function table.Copy( t, lookup_table ) | |
if ( t == nil ) then return nil end | |
local copy = {} | |
setmetatable( copy, debug.getmetatable( t ) ) | |
for i, v in pairs( t ) do | |
if ( not istable( v ) ) then | |
copy[ i ] = v | |
else | |
lookup_table = lookup_table or {} | |
lookup_table[ t ] = copy | |
if ( lookup_table[ v ] ) then | |
copy[ i ] = lookup_table[ v ] -- we already copied this table. reuse the copy. | |
else | |
copy[ i ] = table.Copy( v, lookup_table ) -- not yet copied. copy it. | |
end | |
end | |
end | |
return copy | |
end | |
env = table.Copy(_G) | |
commands.clear = function() | |
os.execute("cls") | |
print([[ __ ________ _ _____ ____ __ __ ______ _____ _____ | |
\ \ / / ____| | / ____/ __ \| \/ | ____| /\ | __ \|_ _| /\ | |
\ \ /\ / /| |__ | | | | | | | | \ / | |__ / \ | |__) | | | / \ | |
\ \/ \/ / | __| | | | | | | | | |\/| | __| / /\ \ | _ / | | / /\ \ | |
\ /\ / | |____| |___| |___| |__| | | | | |____ / ____ \| | \ \ _| |_ / ____ \ | |
\/ \/ |______|______\_____\____/|_| |_|______| /_/ \_\_| \_\_____/_/ \_\ | |
]]) | |
print('Type help for commands.\nType exit to quit.\nLua code is accepted.') | |
end | |
commands.exec = function(input) | |
if(input == "") then | |
print("ERROR: No args!") | |
return | |
end | |
local func, err = loadstring("return " .. input) | |
if func == nil then | |
local func1, err1 = loadstring(input) | |
setfenv(func1,env) | |
if(func1 == nil) then | |
print(err1) | |
else | |
pcall(func1) | |
end | |
else | |
setfenv(func,env) | |
print( select( 2, pcall( func ) ) ) | |
end | |
end | |
local function processargs(str) | |
local splitstr = string.gmatch(str,"%S+") | |
for i in splitstr do | |
print(i) | |
end | |
end | |
--for command, executor in pairs(commands) do print(command) executor() end | |
local currentcommand | |
while currentcommand ~= [[exit]] do | |
currentcommand = io.read() | |
local cmd, args = currentcommand:match("^([^%s]+) ?(.*)$") | |
if cmd == nil then | |
print("ERROR: no comamnd1") | |
end | |
local command = commands[cmd] | |
if command ~= nil then | |
command(args) | |
else | |
commands["exec"](currentcommand) | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment