From f43dc63f9820ba0d3ff30efd2c45bf6dc5d2af51 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Sun, 12 Feb 2012 00:08:53 +1000 Subject: New sendBack and sendForth global functions. --- LuaSL/src/LuaSL.h | 2 ++ LuaSL/src/LuaSL_main.c | 8 -------- LuaSL/src/LuaSL_test.c | 16 +++------------- LuaSL/src/LuaSL_utilities.c | 18 ++++++++++++++++++ 4 files changed, 23 insertions(+), 21 deletions(-) (limited to 'LuaSL/src') diff --git a/LuaSL/src/LuaSL.h b/LuaSL/src/LuaSL.h index 6c672e5..723f00d 100644 --- a/LuaSL/src/LuaSL.h +++ b/LuaSL/src/LuaSL.h @@ -64,6 +64,8 @@ typedef struct void loggingStartup(gameGlobals *game); char *getDateTime(struct tm **nowOut, char *dateOut, time_t *tiemOut); +void sendBack(gameGlobals *game, Ecore_Con_Client *client, const char *SID, const char *message); +void sendForth(gameGlobals *game, const char *SID, const char *message); float timeDiff(struct timeval *now, struct timeval *then); #include "LuaSL_LSL_tree.h" diff --git a/LuaSL/src/LuaSL_main.c b/LuaSL/src/LuaSL_main.c index e209023..41fa45a 100644 --- a/LuaSL/src/LuaSL_main.c +++ b/LuaSL/src/LuaSL_main.c @@ -5,14 +5,6 @@ static int CPUs = 4; static Eina_Strbuf *clientStream; -static void sendBack(gameGlobals *game, Ecore_Con_Client *client, const char *SID, const char *message) -{ - char buf[PATH_MAX]; - - sprintf(buf, "%s.%s\n", SID, message); - ecore_con_client_send(client, buf, strlen(buf)); - ecore_con_client_flush(client); -} static Eina_Bool _add(void *data, int type __UNUSED__, Ecore_Con_Event_Client_Add *ev) { diff --git a/LuaSL/src/LuaSL_test.c b/LuaSL/src/LuaSL_test.c index 90dc5ac..2ca9792 100644 --- a/LuaSL/src/LuaSL_test.c +++ b/LuaSL/src/LuaSL_test.c @@ -89,7 +89,6 @@ static void dirList_compile(const char *name, const char *path, void *data) { gameGlobals *game = data; - char buf[PATH_MAX]; char *ext = rindex(name, '.'); if (ext) @@ -103,9 +102,7 @@ static void dirList_compile(const char *name, const char *path, void *data) snprintf(me->SID, sizeof(me->SID), "%s/%s", path, name); snprintf(me->fileName, sizeof(me->fileName), "%s/%s", path, name); eina_hash_add(game->scripts, me->SID, me); - snprintf(buf, sizeof(buf), "%s/%s.compile()\n", path, name); - ecore_con_server_send(game->server, buf, strlen(buf)); - ecore_con_server_flush(game->server); + sendForth(game, me->SID, "compile()"); } } } @@ -119,11 +116,7 @@ static Eina_Bool _quit_timer_cb(void *data) scripts = eina_hash_iterator_data_new(game->scripts); while(eina_iterator_next(scripts, (void **) &me)) { - char buf[PATH_MAX]; - - snprintf(buf, sizeof(buf), "%s.lua.out.quit()\n", me->SID); - ecore_con_server_send(game->server, buf, strlen(buf)); - ecore_con_server_flush(game->server); + sendForth(game, me->SID, "quit()"); } ecore_con_server_send(game->server, ".exit()\n", 8); @@ -151,7 +144,6 @@ static Eina_Bool _data(void *data, int type __UNUSED__, Ecore_Con_Event_Server_D { gameGlobals *game = data; - char buf[PATH_MAX]; char SID[PATH_MAX]; const char *command; char *ext; @@ -191,9 +183,7 @@ static Eina_Bool _data(void *data, int type __UNUSED__, Ecore_Con_Event_Server_D } } PD("The compile of %s worked, running it now.", SID); - snprintf(buf, sizeof(buf), "%s.lua.out.start()\n", SID); - ecore_con_server_send(game->server, buf, strlen(buf)); - ecore_con_server_flush(game->server); + sendForth(game, SID, "start()"); } else { diff --git a/LuaSL/src/LuaSL_utilities.c b/LuaSL/src/LuaSL_utilities.c index d73c06d..ab4ea65 100644 --- a/LuaSL/src/LuaSL_utilities.c +++ b/LuaSL/src/LuaSL_utilities.c @@ -66,6 +66,24 @@ char *getDateTime(struct tm **nowOut, char *dateOut, time_t *timeOut) return (dateTime); } +void sendBack(gameGlobals *game, Ecore_Con_Client *client, const char *SID, const char *message) +{ + char buf[PATH_MAX]; + + sprintf(buf, "%s.%s\n", SID, message); + ecore_con_client_send(client, buf, strlen(buf)); + ecore_con_client_flush(client); +} + +void sendForth(gameGlobals *game, const char *SID, const char *message) +{ + char buf[PATH_MAX]; + + snprintf(buf, sizeof(buf), "%s.%s\n", SID, message); + ecore_con_server_send(game->server, buf, strlen(buf)); + ecore_con_server_flush(game->server); +} + float timeDiff(struct timeval *now, struct timeval *then) { if (0 == gettimeofday(now, 0)) -- cgit v1.1