Posted 17 October 2012 - 05:04 PM
I figured I would start my first major project, a single terminal to control all turtles connected to it via rednet. I'm sure it's been done before, but not by me, and I have been bored.
What I am asking for is some help figuring out the structure of the program to achieve maximum efficiency. Currently my structure is as follows:
Classes:
Turtle - Used to remember turtles connected to the system as well as track position and issue commands.
Menu - Used to handle menu navigation, display, and execution.
This is my first sticking point. EventHandler is a table such as {["key"] = func} where func is a function designed to handle all "key" events. However, I must pass the menu to this function in order to properly call Menu:up() which moves the menu selection up, not a major issue, but I then have to return that menu in order to keep an up-to-date version to send to the next "key" event. When this is combined with the fact that I must send the 'turtle' table to the menu in order to properly call turtle functions from the menu, it becomes less and less efficient, and even more convoluted.
I have been contemplating a few solutions, but since I am fairly new to the Lua language and environment I would like some more experienced opinions.
1. Global turtle table and menu table.
[indent=1]This looks like the simplest option so far, but I do not fully understand the effects this could have of the program's efficiency.[/indent]
2. Move logic into Menu class.
[indent=1]This looks to be the most efficient to me, but if I introduce sub-menus then I will run into the same problem again.[/indent]
3. Any other suggestions?
What I am asking for is some help figuring out the structure of the program to achieve maximum efficiency. Currently my structure is as follows:
Classes:
Turtle - Used to remember turtles connected to the system as well as track position and issue commands.
Menu - Used to handle menu navigation, display, and execution.
local turtles = Turtle:new()
local menu = Menu:new({"Accept New Turtle",getTurtle},{"Quit",os.shutdown})
while true do
local evt = {os.pullEvent()}
EventHandler[evt[1]](evt,menu)
end
This is my first sticking point. EventHandler is a table such as {["key"] = func} where func is a function designed to handle all "key" events. However, I must pass the menu to this function in order to properly call Menu:up() which moves the menu selection up, not a major issue, but I then have to return that menu in order to keep an up-to-date version to send to the next "key" event. When this is combined with the fact that I must send the 'turtle' table to the menu in order to properly call turtle functions from the menu, it becomes less and less efficient, and even more convoluted.
I have been contemplating a few solutions, but since I am fairly new to the Lua language and environment I would like some more experienced opinions.
1. Global turtle table and menu table.
[indent=1]This looks like the simplest option so far, but I do not fully understand the effects this could have of the program's efficiency.[/indent]
2. Move logic into Menu class.
[indent=1]This looks to be the most efficient to me, but if I introduce sub-menus then I will run into the same problem again.[/indent]
3. Any other suggestions?