view src/luan/init.luan @ 118:735708619119

add Debug.debug() git-svn-id: https://luan-java.googlecode.com/svn/trunk@119 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Sun, 01 Jun 2014 07:07:31 +0000
parents 1ff1c32417eb
children
line wrap: on
line source

--Io.stdout.write "this is init.luan\n"

local function print(...)
	local list = {}
	for v in Basic.values(...) do
		list[#list+1] = to_string(v)
		list[#list+1] = '\t'
	end
	if #list == 0 then
		Io.stdout.write( '\n' )
	else
		list[#list] = '\n'
		Io.stdout.write( Table.unpack(list) )
	end
end

_G.print = print


local Debug = {}
Package.loaded.Debug = Debug
_G.Debug = Debug

function Debug.debug(prompt)
	prompt = prompt or "luan_debug> "
	local function console()
		return Io.read_console_line(prompt)
	end
	for line in console do
		local fn = load(line,"stdin",true)
		local result = Table.pack( fn() )
		if result.n > 0 then
			print( Table.unpack(result,1,result.n) )
		end
	end
end