Posted 11 January 2013 - 02:21 PM
Edit: See my second post (third in the thread). The real problem is variable scope, not anything to do with tables.
Hi, I'm trying to write my own Lua REPL (read-eval-print loop), for two reasons: one, I'd like a better one, and two, I want to run it in parallel with other things. My plan is to use loadstring inside a loop to execute the Lua code input by the user, but I'm running into a problem. The following works under regular Lua 5.1 (on my computer, no Minecraft involved):
But when I execute exactly the same commands inside Minecraft, I get "string:1: index expected, got nil". Loadstring doesn't throw the error, but it's when the resulting function is called that the problem happens.
If instead of trying to stuff something into a table, I just do loadstring('foo=2')(), it works perfectly.
Is this a bug, or am I doing something wrong? Thanks!
Hi, I'm trying to write my own Lua REPL (read-eval-print loop), for two reasons: one, I'd like a better one, and two, I want to run it in parallel with other things. My plan is to use loadstring inside a loop to execute the Lua code input by the user, but I'm running into a problem. The following works under regular Lua 5.1 (on my computer, no Minecraft involved):
Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio
> t={}
> loadstring('t[1]=2')()
> print(t[1])
2
>
But when I execute exactly the same commands inside Minecraft, I get "string:1: index expected, got nil". Loadstring doesn't throw the error, but it's when the resulting function is called that the problem happens.
If instead of trying to stuff something into a table, I just do loadstring('foo=2')(), it works perfectly.
Is this a bug, or am I doing something wrong? Thanks!