Jump to content




lua help os.run. enviroment help please


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

#1 snoble2022

  • Members
  • 100 posts
  • LocationSomewhere near the local computer store?

Posted 10 December 2012 - 04:42 AM

Hello, how do I create an enviroment for os.run. it needs to include everything exceept fs api io api and a file api its using. It also needs to include ( i mean be able to use my other api).vthanks


#2 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 10 December 2012 - 05:31 AM

well if you use os.run(_G,program) it will have the normal environment, if you want to give it its own environment you make a table for that and then let it access the _G table for anything it lacks (you have to include _G so it can still use your existing vars and functions)

local myenviron=setmetatable({},{__index=_G})
os.run(myenviron,program)


#3 faubiguy

  • Members
  • 213 posts

Posted 10 December 2012 - 03:14 PM

os.run automatically makes the environment inherit from _G, so you can't run a program with an environment that doesn't have things that are in _G (with os.run). However you can make it use an environment that overrides variables and functions in _G, such as:
local emptyAPI = setmetatable({}, {__index = function() return function() end end})
local env = {fs = emptyAPI, io = emptyAPI, file = myFileAPI}
os.run(env, "example/program", "argument")

This will make all the functions in fs and io do nothing in the program being run.

#4 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 11 December 2012 - 02:59 AM

hmmm.... it seems my information is out of date. faubiguy is right





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users