95 posts
Location
Somewhere 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
1548 posts
Location
That 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)
231 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.
1548 posts
Location
That dark shadow under your bed...
Posted 11 December 2012 - 02:59 AM
hmmm…. it seems my information is out of date. faubiguy is right