diff options
author | David Walter Seikel | 2016-02-06 00:10:27 +1000 |
---|---|---|
committer | David Walter Seikel | 2016-02-06 00:10:27 +1000 |
commit | cfea61e21e659244fa71ee6b6e27aa5d312723a1 (patch) | |
tree | f293c25c02d4157f85656b5a23e8dddd499b533c | |
parent | Try to actually deal with return() properly. (diff) | |
download | SledjHamr-cfea61e21e659244fa71ee6b6e27aa5d312723a1.zip SledjHamr-cfea61e21e659244fa71ee6b6e27aa5d312723a1.tar.gz SledjHamr-cfea61e21e659244fa71ee6b6e27aa5d312723a1.tar.bz2 SledjHamr-cfea61e21e659244fa71ee6b6e27aa5d312723a1.tar.xz |
Actually use the command hash. A little.
-rw-r--r-- | src/LuaSL/LuaSL_main.c | 84 | ||||
-rw-r--r-- | src/libraries/SledjHamr.c | 2 |
2 files changed, 49 insertions, 37 deletions
diff --git a/src/LuaSL/LuaSL_main.c b/src/LuaSL/LuaSL_main.c index 9a0f32f..f131429 100644 --- a/src/LuaSL/LuaSL_main.c +++ b/src/LuaSL/LuaSL_main.c | |||
@@ -252,45 +252,52 @@ static void _compileCbSingle(LuaCompiler *compiler) | |||
252 | printf("Compile of %s failed!\n", compiler->file); | 252 | printf("Compile of %s failed!\n", compiler->file); |
253 | } | 253 | } |
254 | 254 | ||
255 | static boolean parser(void *data, Connection *connection, char *SID, char *command, char *arguments) | 255 | static boolean _commandCompile(void *data, Connection *connection, char *SID, char *command, char *arguments) |
256 | { | ||
257 | LuaCompiler *compiler; | ||
258 | |||
259 | compiler = createCompiler(SID, arguments, (compileCb) compileLSL, _compileCb); | ||
260 | compiler->client = connection; | ||
261 | PI("Compiling script %s", arguments); | ||
262 | compileScript(compiler, TRUE); | ||
263 | |||
264 | return TRUE; | ||
265 | } | ||
266 | |||
267 | static boolean _commandRun(void *data, Connection *connection, char *SID, char *command, char *arguments) | ||
256 | { | 268 | { |
257 | gameGlobals *ourGlobals = data; | 269 | gameGlobals *ourGlobals = data; |
258 | char buf[PATH_MAX]; | 270 | script *me = scriptAdd(arguments, SID, send2server, ourGlobals); |
259 | 271 | ||
260 | //PD("PARSE COMMAND %s - %s (%s)", SID, command, arguments); | 272 | me->client = connection; |
261 | if (0 == strcmp(command, "compile")) | 273 | eina_hash_add(ourGlobals->names, me->fileName, me); |
262 | { | 274 | me = getScript(SID); |
263 | LuaCompiler *compiler; | 275 | if (me) |
276 | { | ||
277 | PI("Running script %s", me->fileName); | ||
278 | runScript(me); | ||
279 | releaseScript(me); | ||
280 | } | ||
281 | else | ||
282 | PE("Failed to run script %s", me->fileName); | ||
264 | 283 | ||
265 | compiler = createCompiler(SID, arguments, (compileCb) compileLSL, _compileCb); | 284 | return TRUE; |
266 | compiler->client = connection; | 285 | } |
267 | PI("Compiling script %s", arguments); | ||
268 | compileScript(compiler, TRUE); | ||
269 | } | ||
270 | else if (0 == strcmp(command, "run")) | ||
271 | { | ||
272 | script *me = scriptAdd(arguments, SID, send2server, ourGlobals); | ||
273 | 286 | ||
274 | me->client = connection; | 287 | static boolean _commandExit(void *data, Connection *connection, char *SID, char *command, char *arguments) |
275 | eina_hash_add(ourGlobals->names, me->fileName, me); | 288 | { |
276 | me = getScript(SID); | 289 | PI("Told to exit."); |
277 | if (me) | 290 | ecore_main_loop_quit(); |
278 | { | 291 | |
279 | PI("Running script %s", me->fileName); | 292 | return TRUE; |
280 | runScript(me); | 293 | } |
281 | releaseScript(me); | 294 | |
282 | } | 295 | static boolean parser(void *data, Connection *connection, char *SID, char *command, char *arguments) |
283 | else | 296 | { |
284 | PE("Failed to run script %s", me->fileName); | 297 | char buf[PATH_MAX]; |
285 | } | 298 | |
286 | else if (0 == strcmp(command, "exit")) | 299 | //PD("PARSE COMMAND %s - %s (%s)", SID, command, arguments); |
287 | { | 300 | // TODO - This bit might still remain, unless script.return() can make it go away? |
288 | PI("Told to exit."); | ||
289 | ecore_main_loop_quit(); | ||
290 | } | ||
291 | else | ||
292 | { | ||
293 | // TODO - Even after moving the above into the command hash, this bit might still remain, unless script.return() can make it go away. | ||
294 | // Though perhaps the "else" part stays? | 301 | // Though perhaps the "else" part stays? |
295 | // if (0 == strcmp("return", command)) | 302 | // if (0 == strcmp("return", command)) |
296 | // snprintf(buf, sizeof(buf), "%s(%s)", command, arguments); | 303 | // snprintf(buf, sizeof(buf), "%s(%s)", command, arguments); |
@@ -298,7 +305,6 @@ static boolean parser(void *data, Connection *connection, char *SID, char *comma | |||
298 | snprintf(buf, sizeof(buf), "%s(%s)", command, arguments); | 305 | snprintf(buf, sizeof(buf), "%s(%s)", command, arguments); |
299 | //PD("Sending -> script %s : %s", SID, buf); | 306 | //PD("Sending -> script %s : %s", SID, buf); |
300 | send2script(SID, buf); | 307 | send2script(SID, buf); |
301 | } | ||
302 | 308 | ||
303 | return TRUE; | 309 | return TRUE; |
304 | } | 310 | } |
@@ -336,12 +342,18 @@ int main(int argc, char **argv) | |||
336 | } | 342 | } |
337 | else if (ecore_con_init()) | 343 | else if (ecore_con_init()) |
338 | { | 344 | { |
345 | Connection *conn = NULL; | ||
346 | |||
339 | // PD("LuaSL is about to try creating a LuaSL server."); | 347 | // PD("LuaSL is about to try creating a LuaSL server."); |
340 | if (openArms("LuaSL", ourGlobals.address, ourGlobals.port, &ourGlobals, NULL, NULL, NULL, parser, send2parser)) | 348 | if ((conn = openArms("LuaSL", ourGlobals.address, ourGlobals.port, &ourGlobals, NULL, NULL, NULL, parser, send2parser))) |
341 | { | 349 | { |
342 | Eina_Iterator *scripts; | 350 | Eina_Iterator *scripts; |
343 | script *me; | 351 | script *me; |
344 | 352 | ||
353 | eina_hash_add(conn->commands, "compile", _commandCompile); | ||
354 | eina_hash_add(conn->commands, "run", _commandRun); | ||
355 | eina_hash_add(conn->commands, "exit", _commandExit); | ||
356 | |||
345 | result = 0; | 357 | result = 0; |
346 | compilerSetup(&ourGlobals); | 358 | compilerSetup(&ourGlobals); |
347 | 359 | ||
diff --git a/src/libraries/SledjHamr.c b/src/libraries/SledjHamr.c index 1fae167..a217380 100644 --- a/src/libraries/SledjHamr.c +++ b/src/libraries/SledjHamr.c | |||
@@ -319,7 +319,7 @@ static Eina_Bool clientAdd(void *data, int type, Ecore_Con_Event_Client_Add *ev) | |||
319 | conn->_del = connection->_del; | 319 | conn->_del = connection->_del; |
320 | conn->unknownInCommand = connection->unknownInCommand; | 320 | conn->unknownInCommand = connection->unknownInCommand; |
321 | conn->unknownOutCommand = connection->unknownOutCommand; | 321 | conn->unknownOutCommand = connection->unknownOutCommand; |
322 | conn->commands = eina_hash_string_superfast_new(NULL); | 322 | conn->commands = connection->commands; |
323 | ecore_con_client_data_set(ev->client, conn); | 323 | ecore_con_client_data_set(ev->client, conn); |
324 | 324 | ||
325 | if (connection->_add) | 325 | if (connection->_add) |