Mercurial Hosting > luan
diff core/src/luan/modules/Io.luan @ 554:18504c41b0be
move debug() to Io and remove Debug module;
Io.print() now doesn't print newline if there is nothing to be printed;
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 18 Jun 2015 03:30:18 -0600 |
parents | 473e456444ff |
children | 97c8ae330efe |
line wrap: on
line diff
--- a/core/src/luan/modules/Io.luan Thu Jun 18 03:14:07 2015 -0600 +++ b/core/src/luan/modules/Io.luan Thu Jun 18 03:30:18 2015 -0600 @@ -14,17 +14,19 @@ local Luan = require "luan:Luan" -local to_string = Luan.to_string -local type = Luan.type -local try = Luan.try -local ipairs = Luan.ipairs -local pairs = Luan.pairs -local values = Luan.values +local error = Luan.error +local to_string = Luan.to_string or error() +local type = Luan.type or error() +local try = Luan.try or error() +local ipairs = Luan.ipairs or error() +local pairs = Luan.pairs or error() +local values = Luan.values or error() +local load = Luan.load or error() local Table = require "luan:Table" -local unpack = Table.unpack +local unpack = Table.unpack or error() local String = require "luan:String" -local encode = String.encode -local matches = String.matches +local encode = String.encode or error() +local matches = String.matches or error() function M.print_to(out,...) @@ -33,9 +35,7 @@ list[#list+1] = to_string(v) list[#list+1] = '\t' end - if #list == 0 then - out.write( '\n' ) - else + if #list > 0 then list[#list] = '\n' out.write( unpack(list) ) end @@ -122,4 +122,27 @@ end end + +-- debug + +function M.debug(prompt) + prompt = prompt or "luan_debug> " + local function console() + return M.read_console_line(prompt) + end + local env = {} + for line in console do + try { + function() + local fn = load(line,"stdin",env,true) + M.print( fn() ) + end; + catch = function(e) + M.print(e) + end; + } + end +end + + return M