Jump to content




Global Environment Issues


  • You cannot reply to this topic
4 replies to this topic

#1 minecraftwarlock

  • Members
  • 34 posts

Posted 08 May 2015 - 03: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 by minecraftwarlock, 08 May 2015 - 04:35 AM.


#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 08 May 2015 - 05: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.

#3 minecraftwarlock

  • Members
  • 34 posts

Posted 08 May 2015 - 05:25 AM

with
local program = {shell = shell}
I still get the same error

#4 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 08 May 2015 - 05:28 AM

Post the whole code, please. We can't help very effectively if we're just guessing at what you're doing.

#5 minecraftwarlock

  • Members
  • 34 posts

Posted 08 May 2015 - 08:57 PM

Solved it! Used a custom loadAPI function and it worked fine.





3 user(s) are reading this topic

0 members, 3 guests, 0 anonymous users