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
lua help os.run. enviroment help please
Started by snoble2022, Dec 10 2012 04:42 AM
3 replies to this topic
#1
Posted 10 December 2012 - 04:42 AM
#2
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
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:
This will make all the functions in fs and io do nothing in the program being run.
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
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











