From d042b1e2fb8418059f2acef4e5fb803cb73e183f Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Fri, 3 Feb 2012 23:59:13 +1000 Subject: Implement basic states. --- LuaSL/src/LuaSL_LSL_tree.h | 1 + LuaSL/src/LuaSL_compile.c | 27 +++++++++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h index 2a66bd7..8909c7e 100644 --- a/LuaSL/src/LuaSL_LSL_tree.h +++ b/LuaSL/src/LuaSL_LSL_tree.h @@ -293,6 +293,7 @@ struct _LSL_Function { LSL_Text name; LSL_Text type; + const char *state; #if LUASL_DIFF_CHECK // LSL_Leaf *params; // So we store the parenthesis, and their ignorables. // This points to the params leaf, which is a function, pointing to this structure. The actual params are in vars. diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c index 8194947..66f5174 100644 --- a/LuaSL/src/LuaSL_compile.c +++ b/LuaSL/src/LuaSL_compile.c @@ -856,6 +856,9 @@ LSL_Leaf *addState(LuaSL_compiler *compiler, LSL_Leaf *state, LSL_Leaf *identifi if ((identifier) && (result)) { + Eina_Iterator *handlers; + LSL_Function *func; + memcpy(result, &(compiler->state), sizeof(LSL_State)); compiler->state.block = NULL; compiler->state.handlers = NULL; @@ -864,6 +867,11 @@ LSL_Leaf *addState(LuaSL_compiler *compiler, LSL_Leaf *state, LSL_Leaf *identifi result->name.ignorable = identifier->ignorable; identifier->ignorable = NULL; #endif + handlers = eina_hash_iterator_data_new(result->handlers); + while(eina_iterator_next(handlers, (void **) &func)) + { + func->state = result->name.text; + } result->block = block->value.blockValue; if (state) { @@ -2085,10 +2093,15 @@ static void outputFunctionToken(FILE *file, outputMode mode, LSL_Leaf *content) } else if (OM_LUA == mode) { - fprintf(file, "\n\nfunction "); - if (func->type.text) - fprintf(file, " --[[%s]] ", func->type.text); - fprintf(file, "%s(", func->name.text); + if (func->state) + fprintf(file, "\n\n%s.%s = function(", func->state, func->name.text); + else + { + fprintf(file, "\n\nfunction "); + if (func->type.text) + fprintf(file, " --[[%s]] ", func->type.text); + fprintf(file, "%s(", func->name.text); + } EINA_INARRAY_FOREACH((&(func->vars)), param) { // TODO - comment out param types. @@ -2323,14 +2336,16 @@ static boolean doneParsing(LuaSL_compiler *compiler) { fprintf(out, "--// Pre declared helper stuff.\n"); fprintf(out, "local bit = require(\"bit\")\n"); + fprintf(out, "currentState = { state_exit = function() end }\n"); fprintf(out, "function preDecrement(name) _G[name] = _G[name] - 1; return _G[name]; end;\n"); fprintf(out, "function preIncrement(name) _G[name] = _G[name] + 1; return _G[name]; end;\n"); fprintf(out, "function postDecrement(name) local temp = _G[name]; _G[name] = _G[name] - 1; return temp; end;\n"); fprintf(out, "function postIncrement(name) local temp = _G[name]; _G[name] = _G[name] + 1; return temp; end;\n"); - fprintf(out, "function stateChange(x) end;\n"); + fprintf(out, "function stateChange(x) currentState.state_exit(); curruntState = x; currentState.state_entry(); end;\n"); fprintf(out, "--// Generated code goes here.\n\n"); outputLeaf(out, OM_LUA, compiler->ast); - fprintf(out, "\n\n--// End of generated code.\n\n"); +// fprintf(out, "\n\nstateChange(default)\n"); + fprintf(out, "\n--// End of generated code.\n\n"); fclose(out); sprintf(buffer, "../../libraries/luajit-2.0/src/luajit \"%s\"", luaName); count = system(buffer); -- cgit v1.1