IgorTimofeev / MineOS

Home of MineOS and it's software for OpenComputers mod
Other
758 stars 188 forks source link

Function to emulate a computer? #164

Closed atirut-w closed 5 years ago

atirut-w commented 5 years ago

I've been developing my own kernel/OS for a while now, but it's just too annoying to leave the floppy directory and put it in another computer just to test it. Is it possible to emulate a computer so that OS development can get easier?

IgorTimofeev commented 5 years ago

Yep, you can do it via load() environment. But only if your currently running OS doesn't substitute native OpenComputers functions/tables like OpenOS does (in /lib/event.lua, for example):

-- Create sandbox environment table that will be used as global variables source for your OS
local sandbox = {}
for key, value in pairs(_G) do
  sandbox[key] = value
end
sandbox._G = sandbox

-- Run your code in sandbox. It won't change your currently running OS global environment
load(<your lua code string goes here>, "=MyOS.lua", "t", sandbox)