Mercurial Hosting > luan
comparison src/luan/lib/init.luan @ 149:f99fd64291b3
change load() to take env instead of using global
git-svn-id: https://luan-java.googlecode.com/svn/trunk@150 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Mon, 16 Jun 2014 05:47:54 +0000 |
parents | 90f38a5d0e0a |
children | f35c50027985 |
comparison
equal
deleted
inserted
replaced
148:dfd0f33b584e | 149:f99fd64291b3 |
---|---|
48 if Table.pack(...).n > 0 then | 48 if Table.pack(...).n > 0 then |
49 _G.print(...) | 49 _G.print(...) |
50 end | 50 end |
51 end | 51 end |
52 | 52 |
53 function Table.clone(tbl) | |
54 local new = {} | |
55 for k,v in _G.pairs(tbl) do | |
56 new[k] = v | |
57 end | |
58 return new | |
59 end | |
60 | |
53 function Debug.debug(prompt) | 61 function Debug.debug(prompt) |
54 prompt = prompt or "luan_debug> " | 62 prompt = prompt or "luan_debug> " |
55 local function console() | 63 local function console() |
56 return Io.read_console_line(prompt) | 64 return Io.read_console_line(prompt) |
57 end | 65 end |
66 local env = Table.clone(_G) | |
58 for line in console do | 67 for line in console do |
59 try | 68 try |
60 local fn = _G.load(line,"stdin",true,true) | 69 local fn = _G.load(line,"stdin",env,true) |
61 Debug.print_if_something( fn() ) | 70 Debug.print_if_something( fn() ) |
62 catch e do | 71 catch e do |
63 _G.print(e) | 72 _G.print(e) |
64 end | 73 end |
65 end | 74 end |