This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
minecraftwarlock's profile picture

Global Environment Issues

Started by minecraftwarlock, 08 May 2015 - 02:53 AM
minecraftwarlock #1
Posted 08 May 2015 - 04:53 AM
Any time I try to call an api function from the loaded file I get an attempt to index a nil value error.
The environment code:

local program = {}
setmetatable(program, {__index = getfenv(1)})
local prog, err = loadfile(path)
setfenv(prog, program)
prog()

Edit: The problem only occurs when I try to use the shell API

Edit 2: This is the line that errors:

local sPath = shell.resolve( tArgs[1] )
Edited on 08 May 2015 - 03:35 AM
Lyqyd #2
Posted 08 May 2015 - 06:09 AM
Why not just shell.run(path)?

To fix the issue, you'd have to include the shell "api" in the environment table, but shell.run does all of this for you.
minecraftwarlock #3
Posted 08 May 2015 - 06:25 AM
with

local program = {shell = shell}
I still get the same error
Lyqyd #4
Posted 08 May 2015 - 06:28 AM
Post the whole code, please. We can't help very effectively if we're just guessing at what you're doing.
minecraftwarlock #5
Posted 08 May 2015 - 09:57 PM
Solved it! Used a custom loadAPI function and it worked fine.