This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Konlab's profile picture

How to create OS?

Started by Konlab, 16 May 2014 - 04:34 PM
Konlab #1
Posted 16 May 2014 - 06:34 PM
How to create OS?
apemanzilla #2
Posted 16 May 2014 - 08:07 PM
Well, first of all, you should know what an OS is. It's more than a collection of programs and a UI; one of the most core functions of an OS is being able to run two things at the same time. (well, near the same time) In real life, you would also have to monitor and manage hardware, like the CPU, but that's less of a focus here, although you can still add peripheral support.

To be able to run two things at the same time, you first need to understand coroutines. Coroutines are basically separate programs, but they "hand off" control back and forth to do something. For example:

The "parent": this manages the coroutines and hand-off of power.
"Child" 1: this program does something, let's say it watches rednet.
"Child" 2: this program also does something, let's say its a clock.

The parent program will wait for all incoming events, and when it receives an event, it will hand control to each coroutine, giving it the event and details. Rednet messages send an event, so when the parent coroutine finds a rednet message, it will resume running each child program, telling it about the rednet message. But the clock doesn't need the rednet messages, so the clock will just ignore them.

But how does the parent program know to stop one program and resume the other? Well, that's what coroutine yielding is all about. When a coroutine yields, it basically tells the parent program, "I'm done, let other programs run but tell me when there's another event." A couple events yield the coroutine when called - firstly, coroutine.yield. It just yields the coroutine and waits for the coroutine to be resumed again. Second, os.pullEventRaw and os.pullEvent. These are both basically the same as coroutine.yield, however os.pullEvent will also respect terminations. The sleep function sets a timer, and waits for the timer to go off, which sends an event. So, it also includes a yield. Next, the read function. It is more advanced, and yields repeatedly, waiting for char and key events, to add to the string. And finally, rednet.receive waits for a rednet message to come in.

This is how the core of advanced OS's work - like OneOS, Lyqyd OS, and so on. To start, you'll need a coroutine manager that works like the one above - CraftOS even has one built in (the parallels API) but it' snot very powerful and I'd recommend you learn about coroutines and write your own.

AFTER getting coroutines and multitasking down, you can start implementing a UI and programs :)/>
TyDoesMC #3
Posted 17 May 2014 - 03:50 AM
I've created some cool stuff and I don't understand what my code means nor the stuff you said, judging by his rank and
posts in AaP he is no where close to creating an OS nor next year, no offence but I'm a fast learner and I don't know half
the things people post, believe me I don't even know how to create a GUI and I've been learning Lua for about 2 years :D/> good luck and at least try to prove me wrong (I lust might be an idiot) :/ BYE!
CCGrimHaxor #4
Posted 17 May 2014 - 08:57 PM
Get a basic knowladge of gui creation in computercraft. Get a good knowladge of event systems. Make a plan. Get some apis. Watch some ndf-jay tutorials on youtube and you are done.

Replay if you want more info ;)/>
apemanzilla #5
Posted 19 May 2014 - 02:14 PM
Get a basic knowladge of gui creation in computercraft. Get a good knowladge of event systems. Make a plan. Get some apis. Watch some ndf-jay tutorials on youtube and you are done.

Replay if you want more info ;)/>
No. Do NOT use those NDF-Jay tutorials to make an OS. We have FARR too many clones and copies of OS's made from those tutorials and we do NOT need more. Instead, learn how this works, what it does, look at the source for OneOS or other bigger OS's, and write the code yourself.
CCGrimHaxor #6
Posted 19 May 2014 - 02:22 PM
Get a basic knowladge of gui creation in computercraft. Get a good knowladge of event systems. Make a plan. Get some apis. Watch some ndf-jay tutorials on youtube and you are done.

Replay if you want more info ;)/>/>
No. Do NOT use those NDF-Jay tutorials to make an OS. We have FARR too many clones and copies of OS's made from those tutorials and we do NOT need more. Instead, learn how this works, what it does, look at the source for OneOS or other bigger OS's, and write the code yourself.

What I meant by watch NDF-Jay is to get a basic knowladge on how to do it. Don't compleatly copy the code.
awsmazinggenius #7
Posted 19 May 2014 - 02:35 PM
If you are going to make an OS, some things I think you should know are metatables, coroutines, getfenv/setfenv (because we are still on Lua 5.1) and how to handle errors with pcall (which is actually very simple) to make a simple OS that is more than just a print("NoobOS 0.1")
apemanzilla #8
Posted 19 May 2014 - 03:13 PM
If you are going to make an OS, some things I think you should know are metatables, coroutines, getfenv/setfenv (because we are still on Lua 5.1) and how to handle errors with pcall (which is actually very simple) to make a simple OS that is more than just a print("NoobOS 0.1")
Not to mention understanding how to apply these to make sandboxing and multitasking properly.
Konlab #9
Posted 19 May 2014 - 03:57 PM
If you are going to make an OS, some things I think you should know are metatables, coroutines, getfenv/setfenv (because we are still on Lua 5.1) and how to handle errors with pcall (which is actually very simple) to make a simple OS that is more than just a print("NoobOS 0.1")

Ok!
The Noob OS 0.1 coming soon…