Wednesday, 18 September 2013

lua load() output not working as expected

lua load() output not working as expected

So I'm trying to load some lua code from a file, but keep doing something
wrong.
The code does not print(). Is the output going to some stream saved in a
variable? Or what I dunno...
New to lua.
Also same question with binary code instead of text...
> i= io.input("lua1.lua")
> ii = i:read("*a")
> print(ii)
print("hawhaw!")
> env={}
> e=load(ii,nil,"bt",env)
> pcall(e)
> print(pcall(e))
false [string "print("hawhaw!")..."]:1: attempt to call global 'print'
(a nil value)
> local print = print
> e=load(ii,nil,"bt",env)
> print(pcall(e))
true
> pcall(e)
> e()
> print(e())

No comments:

Post a Comment