
local tArgs = { ... }
if #tArgs > 0 then
	print( "This is an interactive Lua prompt." )
	print( "To run a lua program, just type its name." )
	return
end

local bRunning = true
local tEnv = {
	["exit"] = function()
		bRunning = false
	end,
}
setmetatable( tEnv, { __index = getfenv() } )

print( "Interactive Lua prompt." )
print( "Call exit() to exit." )
while bRunning do
	io.write( "lua> " )
	
	local s = io.read()
	local nForcePrint = 0
	local func, e = loadstring( s )
	local func2, e2 = loadstring( "return "..s )
	if not func then
		if func2 then
			func = func2
			e = nil
			nForcePrint = 1
		end
	else
		if func2 then
			func = func2
		end
	end
	
	if func then
        setfenv( func, tEnv )
        local tResults = { pcall( func ) }
        if tResults[1] then
        	local n = 1
        	while (tResults[n + 1] ~= nil) or (n <= nForcePrint) do
        		print( tostring( tResults[n + 1] ) )
        		n = n + 1
        	end
        else
        	print( tResults[2] )
        end
    else
    	print( e )
    end
    
end
