diff options
author | David Walter Seikel | 2014-04-21 18:28:19 +1000 |
---|---|---|
committer | David Walter Seikel | 2014-04-21 18:28:19 +1000 |
commit | 26df7205616dbcf80b60c1ed3c04ebea26975fe9 (patch) | |
tree | 7bc3851bf7eb3232367cdf8dc6894acf6cb51780 /LuaSL/src/LuaSL_main.c | |
parent | GuiLua uses LumbrJack and Runnr from the shared libraries directory at run ti... (diff) | |
download | SledjHamr-26df7205616dbcf80b60c1ed3c04ebea26975fe9.zip SledjHamr-26df7205616dbcf80b60c1ed3c04ebea26975fe9.tar.gz SledjHamr-26df7205616dbcf80b60c1ed3c04ebea26975fe9.tar.bz2 SledjHamr-26df7205616dbcf80b60c1ed3c04ebea26975fe9.tar.xz |
Convert LuaSL to use LumbrJack.
Diffstat (limited to 'LuaSL/src/LuaSL_main.c')
-rw-r--r-- | LuaSL/src/LuaSL_main.c | 80 |
1 files changed, 40 insertions, 40 deletions
diff --git a/LuaSL/src/LuaSL_main.c b/LuaSL/src/LuaSL_main.c index ac0b0c9..0a40712 100644 --- a/LuaSL/src/LuaSL_main.c +++ b/LuaSL/src/LuaSL_main.c | |||
@@ -9,24 +9,24 @@ static Eina_Strbuf *clientStream; | |||
9 | static Eina_Bool _sleep_timer_cb(void *data) | 9 | static Eina_Bool _sleep_timer_cb(void *data) |
10 | { | 10 | { |
11 | script *script = data; | 11 | script *script = data; |
12 | gameGlobals *game = script->game; | 12 | gameGlobals *ourGlobals = script->game; |
13 | 13 | ||
14 | PD("Waking up %s", script->SID); | 14 | PD("Waking up %s", script->SID); |
15 | sendToChannel(game, script->SID, "return 0.0"); | 15 | sendToChannel(ourGlobals, script->SID, "return 0.0"); |
16 | return ECORE_CALLBACK_CANCEL; | 16 | return ECORE_CALLBACK_CANCEL; |
17 | } | 17 | } |
18 | 18 | ||
19 | static Eina_Bool _timer_timer_cb(void *data) | 19 | static Eina_Bool _timer_timer_cb(void *data) |
20 | { | 20 | { |
21 | script *script = data; | 21 | script *script = data; |
22 | gameGlobals *game = script->game; | 22 | gameGlobals *ourGlobals = script->game; |
23 | 23 | ||
24 | PD("Timer for %s", script->SID); | 24 | PD("Timer for %s", script->SID); |
25 | sendToChannel(game, script->SID, "events.timer()"); | 25 | sendToChannel(ourGlobals, script->SID, "events.timer()"); |
26 | return ECORE_CALLBACK_RENEW; | 26 | return ECORE_CALLBACK_RENEW; |
27 | } | 27 | } |
28 | 28 | ||
29 | static script *findThem(gameGlobals *game, const char *base, const char *text) | 29 | static script *findThem(gameGlobals *ourGlobals, const char *base, const char *text) |
30 | { | 30 | { |
31 | char name[PATH_MAX]; | 31 | char name[PATH_MAX]; |
32 | char *temp; | 32 | char *temp; |
@@ -38,12 +38,12 @@ static script *findThem(gameGlobals *game, const char *base, const char *text) | |||
38 | if ((temp = rindex(name, '"'))) | 38 | if ((temp = rindex(name, '"'))) |
39 | temp[0] = '\0'; | 39 | temp[0] = '\0'; |
40 | strcat(name, ".lsl"); | 40 | strcat(name, ".lsl"); |
41 | return eina_hash_find(game->names, name); | 41 | return eina_hash_find(ourGlobals->names, name); |
42 | } | 42 | } |
43 | 43 | ||
44 | static void resetScript(script *victim) | 44 | static void resetScript(script *victim) |
45 | { | 45 | { |
46 | gameGlobals *game = victim->game; | 46 | gameGlobals *ourGlobals = victim->game; |
47 | 47 | ||
48 | PD("Resetting %s", victim->fileName); | 48 | PD("Resetting %s", victim->fileName); |
49 | // TODO - now what? | 49 | // TODO - now what? |
@@ -52,7 +52,7 @@ static void resetScript(script *victim) | |||
52 | void scriptSendBack(void * data) | 52 | void scriptSendBack(void * data) |
53 | { | 53 | { |
54 | scriptMessage *message = data; | 54 | scriptMessage *message = data; |
55 | gameGlobals *game = message->script->game; | 55 | gameGlobals *ourGlobals = message->script->game; |
56 | 56 | ||
57 | if (0 == strncmp(message->message, "llSleep(", 8)) | 57 | if (0 == strncmp(message->message, "llSleep(", 8)) |
58 | ecore_timer_add(atof(&(message->message)[8]), _sleep_timer_cb, message->script); | 58 | ecore_timer_add(atof(&(message->message)[8]), _sleep_timer_cb, message->script); |
@@ -72,7 +72,7 @@ void scriptSendBack(void * data) | |||
72 | { | 72 | { |
73 | script *them; | 73 | script *them; |
74 | 74 | ||
75 | if ((them = findThem(game, message->script->fileName, &(message->message[18])))) | 75 | if ((them = findThem(ourGlobals, message->script->fileName, &(message->message[18])))) |
76 | { | 76 | { |
77 | char *temp = rindex(&(message->message[18]), ','); | 77 | char *temp = rindex(&(message->message[18]), ','); |
78 | 78 | ||
@@ -82,9 +82,9 @@ void scriptSendBack(void * data) | |||
82 | while (isspace(*temp)) | 82 | while (isspace(*temp)) |
83 | temp++; | 83 | temp++; |
84 | if ('1' == *temp) | 84 | if ('1' == *temp) |
85 | sendToChannel(game, them->SID, "start()"); | 85 | sendToChannel(ourGlobals, them->SID, "start()"); |
86 | else | 86 | else |
87 | sendToChannel(game, them->SID, "stop()"); | 87 | sendToChannel(ourGlobals, them->SID, "stop()"); |
88 | PD("Stopped %s", them->fileName); | 88 | PD("Stopped %s", them->fileName); |
89 | } | 89 | } |
90 | else | 90 | else |
@@ -103,13 +103,13 @@ void scriptSendBack(void * data) | |||
103 | { | 103 | { |
104 | script *them; | 104 | script *them; |
105 | 105 | ||
106 | if ((them = findThem(game, message->script->fileName, &(message->message[20])))) | 106 | if ((them = findThem(ourGlobals, message->script->fileName, &(message->message[20])))) |
107 | resetScript(them); | 107 | resetScript(them); |
108 | } | 108 | } |
109 | else if (0 == strncmp(message->message, "llResetScript(", 14)) | 109 | else if (0 == strncmp(message->message, "llResetScript(", 14)) |
110 | resetScript(message->script); | 110 | resetScript(message->script); |
111 | else | 111 | else |
112 | sendBack(game, message->script->client, message->script->SID, message->message); | 112 | sendBack(ourGlobals, message->script->client, message->script->SID, message->message); |
113 | free(message); | 113 | free(message); |
114 | } | 114 | } |
115 | 115 | ||
@@ -121,7 +121,7 @@ static Eina_Bool _add(void *data, int type __UNUSED__, Ecore_Con_Event_Client_Ad | |||
121 | 121 | ||
122 | static Eina_Bool _data(void *data, int type __UNUSED__, Ecore_Con_Event_Client_Data *ev) | 122 | static Eina_Bool _data(void *data, int type __UNUSED__, Ecore_Con_Event_Client_Data *ev) |
123 | { | 123 | { |
124 | gameGlobals *game = data; | 124 | gameGlobals *ourGlobals = data; |
125 | char buf[PATH_MAX]; | 125 | char buf[PATH_MAX]; |
126 | char SID[PATH_MAX]; | 126 | char SID[PATH_MAX]; |
127 | const char *command; | 127 | const char *command; |
@@ -154,28 +154,28 @@ static Eina_Bool _data(void *data, int type __UNUSED__, Ecore_Con_Event_Client_D | |||
154 | temp[0] = '\0'; | 154 | temp[0] = '\0'; |
155 | 155 | ||
156 | PD("Compiling %s, %s.", SID, file); | 156 | PD("Compiling %s, %s.", SID, file); |
157 | if (compileLSL(game, ev->client, SID, file, FALSE)) | 157 | if (compileLSL(ourGlobals, ev->client, SID, file, FALSE)) |
158 | { | 158 | { |
159 | script *me = calloc(1, sizeof(script)); | 159 | script *me = calloc(1, sizeof(script)); |
160 | 160 | ||
161 | gettimeofday(&me->startTime, NULL); | 161 | gettimeofday(&me->startTime, NULL); |
162 | strncpy(me->SID, SID, sizeof(me->SID)); | 162 | strncpy(me->SID, SID, sizeof(me->SID)); |
163 | strncpy(me->fileName, file, sizeof(me->fileName)); | 163 | strncpy(me->fileName, file, sizeof(me->fileName)); |
164 | me->game = game; | 164 | me->game = ourGlobals; |
165 | me->client = ev->client; | 165 | me->client = ev->client; |
166 | eina_hash_add(game->scripts, me->SID, me); | 166 | eina_hash_add(ourGlobals->scripts, me->SID, me); |
167 | eina_hash_add(game->names, me->fileName, me); | 167 | eina_hash_add(ourGlobals->names, me->fileName, me); |
168 | sendBack(game, ev->client, SID, "compiled(true)"); | 168 | sendBack(ourGlobals, ev->client, SID, "compiled(true)"); |
169 | } | 169 | } |
170 | else | 170 | else |
171 | sendBack(game, ev->client, SID, "compiled(false)"); | 171 | sendBack(ourGlobals, ev->client, SID, "compiled(false)"); |
172 | } | 172 | } |
173 | else if (0 == strcmp(command, "run()")) | 173 | else if (0 == strcmp(command, "run()")) |
174 | { | 174 | { |
175 | script *me; | 175 | script *me; |
176 | char buf[PATH_MAX]; | 176 | char buf[PATH_MAX]; |
177 | 177 | ||
178 | me = eina_hash_find(game->scripts, SID); | 178 | me = eina_hash_find(ourGlobals->scripts, SID); |
179 | if (me) | 179 | if (me) |
180 | { | 180 | { |
181 | sprintf(buf, "%s.lua.out", me->fileName); | 181 | sprintf(buf, "%s.lua.out", me->fileName); |
@@ -191,7 +191,7 @@ static Eina_Bool _data(void *data, int type __UNUSED__, Ecore_Con_Event_Client_D | |||
191 | { | 191 | { |
192 | const char *status = NULL; | 192 | const char *status = NULL; |
193 | 193 | ||
194 | status = sendToChannel(game, SID, command); | 194 | status = sendToChannel(ourGlobals, SID, command); |
195 | if (status) | 195 | if (status) |
196 | PE("Error sending command %s to script %s : %s", command, SID, status); | 196 | PE("Error sending command %s to script %s : %s", command, SID, status); |
197 | } | 197 | } |
@@ -206,7 +206,7 @@ static Eina_Bool _data(void *data, int type __UNUSED__, Ecore_Con_Event_Client_D | |||
206 | 206 | ||
207 | static Eina_Bool _del(void *data, int type __UNUSED__, Ecore_Con_Event_Client_Del *ev) | 207 | static Eina_Bool _del(void *data, int type __UNUSED__, Ecore_Con_Event_Client_Del *ev) |
208 | { | 208 | { |
209 | gameGlobals *game = data; | 209 | gameGlobals *ourGlobals = data; |
210 | 210 | ||
211 | if (ev->client) | 211 | if (ev->client) |
212 | { | 212 | { |
@@ -219,31 +219,31 @@ static Eina_Bool _del(void *data, int type __UNUSED__, Ecore_Con_Event_Client_De | |||
219 | 219 | ||
220 | int main(int argc, char **argv) | 220 | int main(int argc, char **argv) |
221 | { | 221 | { |
222 | gameGlobals game; | 222 | gameGlobals ourGlobals; |
223 | int result = EXIT_FAILURE; | 223 | int result = EXIT_FAILURE; |
224 | 224 | ||
225 | memset(&game, 0, sizeof(gameGlobals)); | 225 | memset(&ourGlobals, 0, sizeof(gameGlobals)); |
226 | game.address = "127.0.0.1"; | 226 | ourGlobals.address = "127.0.0.1"; |
227 | game.port = 8211; | 227 | ourGlobals.port = 8211; |
228 | 228 | ||
229 | if (eina_init()) | 229 | if (eina_init()) |
230 | { | 230 | { |
231 | loggingStartup(&game); | 231 | ourGlobals.logDom = loggingStartup("LuaSL", ourGlobals.logDom); |
232 | game.scripts = eina_hash_string_superfast_new(NULL); | 232 | ourGlobals.scripts = eina_hash_string_superfast_new(NULL); |
233 | game.names = eina_hash_string_superfast_new(NULL); | 233 | ourGlobals.names = eina_hash_string_superfast_new(NULL); |
234 | if (ecore_con_init()) | 234 | if (ecore_con_init()) |
235 | { | 235 | { |
236 | if (ecore_con_init()) | 236 | if (ecore_con_init()) |
237 | { | 237 | { |
238 | if ((game.server = ecore_con_server_add(ECORE_CON_REMOTE_TCP, game.address, game.port, &game))) | 238 | if ((ourGlobals.server = ecore_con_server_add(ECORE_CON_REMOTE_TCP, ourGlobals.address, ourGlobals.port, &ourGlobals))) |
239 | { | 239 | { |
240 | ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_ADD, (Ecore_Event_Handler_Cb) _add, &game); | 240 | ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_ADD, (Ecore_Event_Handler_Cb) _add, &ourGlobals); |
241 | ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DATA, (Ecore_Event_Handler_Cb) _data, &game); | 241 | ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DATA, (Ecore_Event_Handler_Cb) _data, &ourGlobals); |
242 | ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DEL, (Ecore_Event_Handler_Cb) _del, &game); | 242 | ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DEL, (Ecore_Event_Handler_Cb) _del, &ourGlobals); |
243 | ecore_con_server_timeout_set(game.server, 0); | 243 | ecore_con_server_timeout_set(ourGlobals.server, 0); |
244 | ecore_con_server_client_limit_set(game.server, -1, 0); | 244 | ecore_con_server_client_limit_set(ourGlobals.server, -1, 0); |
245 | ecore_con_server_timeout_set(game.server, 10); | 245 | ecore_con_server_timeout_set(ourGlobals.server, 10); |
246 | ecore_con_server_client_limit_set(game.server, 3, 0); | 246 | ecore_con_server_client_limit_set(ourGlobals.server, 3, 0); |
247 | clientStream = eina_strbuf_new(); | 247 | clientStream = eina_strbuf_new(); |
248 | 248 | ||
249 | if (edje_init()) | 249 | if (edje_init()) |
@@ -251,7 +251,7 @@ int main(int argc, char **argv) | |||
251 | int i; | 251 | int i; |
252 | 252 | ||
253 | result = 0; | 253 | result = 0; |
254 | compilerSetup(&game); | 254 | compilerSetup(&ourGlobals); |
255 | luaprocInit(); | 255 | luaprocInit(); |
256 | for (i = 0; i < CPUs; i++) | 256 | for (i = 0; i < CPUs; i++) |
257 | { | 257 | { |
@@ -402,7 +402,7 @@ static int errFunc(lua_State *L) | |||
402 | return 0; | 402 | return 0; |
403 | } | 403 | } |
404 | 404 | ||
405 | void runLuaFile(gameGlobals *game, const char *filename) | 405 | void runLuaFile(gameGlobals *ourGlobals, const char *filename) |
406 | { | 406 | { |
407 | PD("Starting %s", filename); | 407 | PD("Starting %s", filename); |
408 | newProc(filename, TRUE); | 408 | newProc(filename, TRUE); |