Posted 23 September 2013 - 09:54 PM
Hey, earlier today I started thinking about if a form of program multitasking is possible in Lua / Computercraft.
Essentially, either have a custom OS that has certain file setups, which loads all the files that need to be run, and this is the part I'm not sure is possible. Sequentially go through each of the files, and append each line to a table.
So what I mean is say I start an edit program, then I start a chat monitor or peripheral monitor, two different files, and on load of the files, it splits them up so that say programs[1][500] returns the line string to be ran, then programs[2][500] does the same, so an expandable sequential program runner, i guess sort of like multithreading or the parallel api, but not. Is this possible? also would it be possible if compliled to bytecode, how does that work, tried it out today, and could not get it to work properly.
so not sure how lua interprets code, but in this case
So in a sense
program[1][1] = 'str = "Hello World"'
program[1][2] = 'str = "Goodbye World"'
program[2][1] = 'function output(msg)'
program[2][2] = 'function output(msg)'
Thats how Im sort of thinking breaking it down, then its an easy matter to iterate over
Is that possible to be broken down into sequential small steps so the perception of many programs running simultaneously is fluid. Yes i do know about the parallel api and the coroutine functions, but I don't believe this comes under those. I was almost thinking along the lines of machine language, how each step or group of steps is ran, then another programs bit of code can be run, then switch back.
Essentially, either have a custom OS that has certain file setups, which loads all the files that need to be run, and this is the part I'm not sure is possible. Sequentially go through each of the files, and append each line to a table.
So what I mean is say I start an edit program, then I start a chat monitor or peripheral monitor, two different files, and on load of the files, it splits them up so that say programs[1][500] returns the line string to be ran, then programs[2][500] does the same, so an expandable sequential program runner, i guess sort of like multithreading or the parallel api, but not. Is this possible? also would it be possible if compliled to bytecode, how does that work, tried it out today, and could not get it to work properly.
so not sure how lua interprets code, but in this case
str = "Hello World"
function output(msg)
print(msg)
end
output(str)
str = "Goodbye World"
function output(msg)
print(msg)
end
output(str)
So in a sense
program[1][1] = 'str = "Hello World"'
program[1][2] = 'str = "Goodbye World"'
program[2][1] = 'function output(msg)'
program[2][2] = 'function output(msg)'
Thats how Im sort of thinking breaking it down, then its an easy matter to iterate over
Is that possible to be broken down into sequential small steps so the perception of many programs running simultaneously is fluid. Yes i do know about the parallel api and the coroutine functions, but I don't believe this comes under those. I was almost thinking along the lines of machine language, how each step or group of steps is ran, then another programs bit of code can be run, then switch back.