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

Developing for OpenTerminalOS Megathread

Started by cyanisaac, 01 June 2015 - 07:49 PM
cyanisaac #1
Posted 01 June 2015 - 09:49 PM
EDIT: I WILL BE MOVING THIS TO GOOGLE DOCS SOON!

This topic will teach you what you need to know to develop for OpenTerminal. It is a megathread that will contain everything you need to know.

BasicsThe basics of OpenTerminalOS development are pretty simple.
For most applications all you will need to do is grab some information that will allow you to display things in the proper color and format. This is done for you with the API.

Notification Functions:
To warn a user, use OTOS.warn(string warnString).
Similarly, to error a user, use OTOS.error(string errorString)
Finally, to notify a user positively, use OTOS.notify(string notifyString)

Grabbing data as of S3 (coming soon)
In the event that you need to manually grab data (such as text color and background color) you can use OTOS.fetch(string fetchKey)
You can fetch anything in the OTOS api that you can find in the array dataArray (in the OTOS api).
You can find that here: http://pastebin.com/nRymdzYe

Grabbing data for S2 and below.
S2 and below do not include the OTOS.fetch() program. We recommend waiting to work on your programs until this has been implemented as it is a pain to fix.
If you insist on doing it the hard way and grabbing them instead of waiting for S3 to release, please simply grab them by setting your variable equal to the variables in OTOSapi.
DO NOT SET THE VARIABLES! THIS WILL MESS UP OTOS!

If there are any issues with the documentation let me know, otherwise all discussion goes on the forum thread here:http://www.computerc...review-edition/ or the subreddit here: http://reddit.com/r/otos.
Edited on 26 June 2015 - 04:24 PM
biggest yikes #2
Posted 03 June 2015 - 09:40 PM
Apparently S5 will include addons that can be envoked with OTOS.hook, how will this work?
Edited on 03 June 2015 - 07:41 PM
cyanisaac #3
Posted 04 June 2015 - 01:03 AM
Apparently S5 will include addons that can be envoked with OTOS.hook, how will this work?

At some point I plan on including addons that will let people change the OS drastically. Addons are going to have a lot of control over the operating system. Basically OTOS.hook() will authorize an addon, and it will generate some code to verify that it's allowed to (todo: figure out how to do that).

The reason why OTOS.hook() exists is because I don't want things just being able to go ahead and brute force change how OTOS works - which would allow for malicious scripts o' plenty.

Also in case your curious addons might be the same thing as profiles in ME, I have yet to decide what do with that. Don't get excited about this stuff yet though, it's months away.

Lol I'm removing that from the code too, until I'm ready to approach addons lol.
FUNCTION MAN! #4
Posted 06 June 2015 - 01:09 AM
I still don't see the point of OTOS.fetch.
biggest yikes #5
Posted 06 June 2015 - 01:59 AM
I still don't see the point of OTOS.fetch.
You can set the variables (like OTOS.version = "") in S2 and below, but with OTOS.fetch you can't set it (albeit you can override OTOS.fetch to still break stuff)
Edited on 05 June 2015 - 11:59 PM
FUNCTION MAN! #6
Posted 08 June 2015 - 12:37 AM
Still no point.


--#stuff and things go here, like
_G.otos = {}
otos.version = "mything"
--#after every declaration is done,

local _nativesmt = setmetatable --#override the setmetable function to allow for 'read only' metatables
function _G.setmetatable(t, mt)
   if getmetatable(t) ~= nil and getmetatable(t).isReadOnly then --# is there a read only metatable installed?
	  error('attempt to set metatable of read only table') --# there is?! you can't override it, son
   else
	   return _nativesmt(t, mt) --#there isn't. so we call the native set metatable method to set the metatable of a table
   end
end

setmetatble(otos, { --# set otos' metatable
   ['__newindex'] = function(t,k,v) return end, --# __newindex is the meta-method that controls creation of indexes, effectively making this a read only table
   ['isReadOnly'] = true --# set that read only flag we check for in setmetatable to 'lock down' the metatable
}
--[[
# of course, there are still some disadvantages, such as
# getmetatable(otos).isReadOnly = false, that would allow for the metatable to be overriden
# still, this is better then having to use OTOS.fetch
# of course, you can change the variable name from "otos" to "OTOS" or to "myConfigurationAndStuff", the name is just an example
# you could also wish to make a function to make a table read only
]]--
Edited on 07 June 2015 - 10:42 PM
biggest yikes #7
Posted 09 June 2015 - 11:27 PM

# getmetatable(otos).isReadOnly = false, that would allow for the metatable to be overriden
does not not undermine the purpose?

either way, I think the creator hasn't used metatables before, I sure haven't.
Edited on 09 June 2015 - 09:28 PM
cyanisaac #8
Posted 12 June 2015 - 05:55 AM
I am going to lock this thread for now, I will reopen it when I have actual documentation to show and APIs to showcase. It will be a while. Until then either figure it out yourself by looking in the APIs, or just ask me :)/>

Edit: Thanks Lyqyd :(/>
Edited on 26 June 2015 - 04:25 PM
Lyqyd #9
Posted 12 June 2015 - 07:37 AM
I'm leaving this unlocked as there's no pressing need to lock it only to have to unlock it later.