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

Top Level Coroutine Override Lua5.2+ [full control over coroutines]

Started by Piorjade, 16 September 2016 - 09:03 AM
Piorjade #1
Posted 16 September 2016 - 11:03 AM
Is now much smaller than the original and is Lua 5.2+ compatible


While messing around with the idea of a linux-like OS and seeing stuff like the awesome FakeOS…
I saw THAT, made by NeverCast. The thing is, he's offline since 2014 and the code is kinda broken in the new versions of ComputerCraft.

While thinking it was an amazing idea and that it should still work I started rewriting the script by hand (just to understand the code, idk why that works with me) and trying various things out.

I even let the code print it's status step-by-step just to see where the hell it crashed and I even had to look at the shell and bios.lua file. (Yeah it's not that hard and this sounds fucking stupid but leave me alone :(/> )

Then I noticed this:
  • The bios does not wait for an input when the shell exits
  • The bios doesn't start a timer when the shell exits
  • It simply shuts the OS down
  • The code sets awkward stages that do not longer matter BECAUSE the bios doesn't wait for anything (anymore… idk if it did that in 2013/14)
  • The way NeverCast searched for 'shell' didn't work (anymore)
So I did this:
  • Redirected every 'fake' new Event directly to the stage "biosexit"
  • Reworked the way we search for 'shell' with getfenv()
  • Added in a 'tutorial' how to add your own program to the "queue"
  • UPDATE: The code doesn't search for shell anymore, in fact it only queues "terminate" as event and rewrites printError before that (idea by apemanzilla) (I could've queued "rednet_message",0 too, buuuuut it doesn't matter)
(Easy, right? :D/> )

Information for people who didn't know about NeverCast's script:
  • This program "injects" your program(s) way before CraftOS gets loaded, that means that your program(s) will run at the same level (the complete top) , having access to all coroutines. (for example you could get rid of CraftOS and let your own OS boot, not leaving the user the ability to get to CraftOS (could be useful for linux-like OSes) or you could make your own rednet implementation)
  • For example: You could run an antivirus/AppUpdater to scan/update your applications, while using something else… e.g. an OS or play a game or code something… EDIT: For those who like having them running without leaving programs the ability to somehow crash it. (Idk if thats true, sry if I'm wrong)
  • My idea would be for example checking for updates in an OS in the background and notifying the user when an update is available
How to get it:


pastebin get yzfDMjwf injectmystuff

NeverCast's code:


pastebin get 2SQAzrWi startup

[attachment=2660:Capture.PNG]
Edited on 23 September 2016 - 03:48 PM
Lyqyd #2
Posted 16 September 2016 - 03:31 PM
TLCO doesn't let you avoid using coroutines for multitasking. It's essentially just used to replace the shell/multishell and rednet coroutines by causing one of those two coroutines to crash, then replacing the function that's called after those coroutines exit so that whatever custom coroutine manager is desired can manage all of the tasks being run on that computer.
Piorjade #3
Posted 16 September 2016 - 05:34 PM
Ah I get it now, thanks :)/>

I still think that it's really nice, mainly because we can use our own versions of rednet and (completely?) get "rid" of CraftOS (for example if someone wants to make an OS (linux-like or something..) ) :)/>
ry00000 #4
Posted 17 September 2016 - 02:52 PM
I can see this coming in handy for malicious scripts of sorts.
Piorjade #5
Posted 17 September 2016 - 03:37 PM
I can see this coming in handy for malicious scripts of sorts.

In theory, yes.
Practically this is not really malicious on itself.

So it's none of my business if someone makes a virus heh :D/>
Edited on 18 September 2016 - 07:20 PM
Sewbacca #6
Posted 17 September 2016 - 05:24 PM
What does getfenv(number)?
Edited on 17 September 2016 - 03:24 PM
KingofGamesYami #7
Posted 17 September 2016 - 06:12 PM
it gets the function environment at that level in the stack.
Sewbacca #8
Posted 17 September 2016 - 06:35 PM
it gets the function environment at that level in the stack.

Or the given function as an argument. Thanks ^^
apemanzilla #9
Posted 19 September 2016 - 06:41 PM
it gets the function environment at that level in the stack.

Or the given function as an argument. Thanks ^^

Well you asked specifically about getfenv(number) and not getfenv(function) soo