view core/src/luan/modules/Debug.luan @ 360:cbb94a7c7a9e

allow mail attachments; add String.to_binary and Binary.to_string;
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 15 Apr 2015 11:32:30 -0600
parents db37d6aee4db
children 92c3d22745b8
line wrap: on
line source

local Luan = require "luan:Luan"
local load = Luan.load
local try = Luan.try
local Io = require "luan:Io"
local print = Io.print
local Table = require "luan:Table"


function print_if_something(...)
	if Table.pack(...).n > 0 then
		print(...)
	end
end

function debug(prompt)
	prompt = prompt or "luan_debug> "
	local function console()
		return Io.read_console_line(prompt)
	end
	local env = {}
	for line in console do
		try {
			function()
				local fn = load(line,"stdin",env,true)
				print_if_something( fn() )
			end;
			catch = function(e)
				print(e)
			end;
		}
	end
end