lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I was trying to define the system in a table, so upon initialization it could pass the particular system to the controller (and the controller could generically handle many different sequences).  I'm trying to make the source look like:

controller (generic library, static)
state table definition (very readable table, defining the multiple steps of each process). 
custom library (implementation functions of each step)

I was a bit sloppy (it was late) when coming up with the example.  Here's an what I have working now:


-- The function table
system = {
    menu = {
                prepare = function(data)
                    todo = mymodule.build_process1(data)
                    if todo then
                        state = {"system.menu.process1",system.menu.process1}
                        return dispatch(todo)
                    end
                    return errorOut("prepare: mymodule.build_process1 failed")
                end,
                .....

prepare() always starts a sequence.  After that, controller is polled and does this:

            if type(state[2]) == "function" then
                print("Calling: "..state[1])
                ok,ret = pcall(state[2],data)
                if ok then
                    ret = ret or "0"
                    print("Return: "..state[1]..": "..ret)
                    return ret
                end
                return errorOut("ERROR: "..state[1].." No Return")
            end

so, when system.menu has to execute, it needs to walk through:  system.menu.process1(), system.menu.process2(), ... unit it's finished.  These steps are sequential, but can error out if something doesn't work.

I think I'm making this too hard, it's just evolved into this, and I need a fresh perspective.

Thanks!
Mike