Closed Pizzn closed 7 years ago
load()
is the same as if you have executed a file from the command line(hint: dofile()
) in that they don't have the helper modules pre-loaded like the lua
shell has. To resolve this you should require("computer")
or if you want to name it a specific value comp = require("computer")
.
P.S. You will also find that component
isn't pre-loaded for you either
Thanks for the fast reply, but I should have mentioned that I get the exact same behaviour when loading the libs via require(). Using global variables in the script just prints a newline if executed.
load
by default passes current execution env, not passing any local variables, so your second screenshoot is expected behavior. Though it seems that there is bug in lua interpreter not passing current env in load* functions. @payonel
It's been bothering me, why do some of your screen shots show Lua 5.3 and others show 5.2? Is this a world that you've updated many times with? If so do you get the same result if you craft a fresh OpenOS floppy and a fresh CPU?
Yeah, the first screens were made in my actual world. But all cases were re-tested in a fresh world with OC as only mod, using a computer spawned by /oc_spawnComputer.
@magik6k thanks for pointing that out - I'll fix that
@pizzn the issue that @magik6k pointed out:
there is bug in lua interpreter not passing current env in load* functions
Is the only issue I see here, otherwise things work as expected.
d1b7cb977f3e42f158b066108e2c4d9ea4a0c3f4
Whenever I try to execute load()'ed code pointing to any of the Component API, I get "attempt to index a nil value". Does not happen if using Lua API. Additionally, loadfile() always returns nil, or the usual error if not providing any args.
Using OC 1.6.2.7, MC 1.10.2, Forge 2185.