Persistent programs - The-Riddler/CCKernel GitHub Wiki

This is the type of program I designed the kernel to operate with. Persistent programs have an indefinitely long life and will persist until they terminate themselves or error.

##Building a persistent program A persistent program returns a table containing information about it, this table tells the process manger how it should treat the process. An example of a return is below (taken from wnet).

return {
    ["name"] = "wnet",
    ["hooks"] = {
        --["think"] = wnet.checkPackets,
        ["rednet_message"] = wnet.callback,
        ["terminate"] = cleanup,
        ["think"] = cleanUpPacketList
    }
}

There is a number of fields available each with an important purpose, each is listed below with an explanation

#Name The name field denotes the default name the process should be given if the calling process did not allocate one for it. This field is not mandatory

#Hooks The hooks field is a table, the tables keys represent the hook you wish to attach to, and the argument can be either a function (as above) or a numerically indexed table containing a list of functions.

#Main The Main field should be provided a function and one function only. The main function will behave just as you would expect a regular CC Lua file to. A call to os.PullEvent() will cause it to break and resume when an even is triggered. Basically, this behaves as normal.

##Side notes The return does not necessarily half to be hard-coded as above. The initial Lua can be used to dynamically create one based on the arguments supplied to the script. A good example of this and the flexibility it allows is test.lua