diff options
author | David Walter Seikel | 2016-02-05 21:23:50 +1000 |
---|---|---|
committer | David Walter Seikel | 2016-02-05 21:23:50 +1000 |
commit | e4d4a5657c36231f3fc02b9def6ebb193cf95f15 (patch) | |
tree | 44e5c326e9436133815e6da658716dba51d63d7d /src/LuaSL | |
parent | A little bit of clean up of the Lua network messaging TODO. (diff) | |
download | SledjHamr-e4d4a5657c36231f3fc02b9def6ebb193cf95f15.zip SledjHamr-e4d4a5657c36231f3fc02b9def6ebb193cf95f15.tar.gz SledjHamr-e4d4a5657c36231f3fc02b9def6ebb193cf95f15.tar.bz2 SledjHamr-e4d4a5657c36231f3fc02b9def6ebb193cf95f15.tar.xz |
More Lua network messages clean ups.
Highlights -
Properly deal with ( and ).
"return x" -> "return(x)". No more special casing.
Diffstat (limited to 'src/LuaSL')
-rw-r--r-- | src/LuaSL/LuaSL_main.c | 103 |
1 files changed, 51 insertions, 52 deletions
diff --git a/src/LuaSL/LuaSL_main.c b/src/LuaSL/LuaSL_main.c index cf3c946..9a0f32f 100644 --- a/src/LuaSL/LuaSL_main.c +++ b/src/LuaSL/LuaSL_main.c | |||
@@ -41,7 +41,7 @@ static Eina_Bool _sleep_timer_cb(void *data) | |||
41 | script *script = data; | 41 | script *script = data; |
42 | 42 | ||
43 | // PD("Waking up %s", script->name); | 43 | // PD("Waking up %s", script->name); |
44 | send2script(script->SID, "return 0.0"); | 44 | send2script(script->SID, "return(0.0)"); |
45 | return ECORE_CALLBACK_CANCEL; | 45 | return ECORE_CALLBACK_CANCEL; |
46 | } | 46 | } |
47 | 47 | ||
@@ -89,28 +89,28 @@ static boolean send2parser(void *data, Connection *connection, char *SID, char * | |||
89 | return FALSE; | 89 | return FALSE; |
90 | } | 90 | } |
91 | 91 | ||
92 | sprintf(buf, "%s(%s", command, arguments); | 92 | sprintf(buf, "%s(%s)", command, arguments); |
93 | 93 | ||
94 | //PD("GOT MESSAGE from script %s - '%s'", me->name, buf); | 94 | //PD("GOT MESSAGE from script %s - '%s'", me->name, buf); |
95 | 95 | ||
96 | if (0 == strncmp(buf, "llSleep(", 8)) | 96 | if (0 == strcmp(command, "llSleep")) |
97 | ecore_timer_add(atof(&(buf)[8]), _sleep_timer_cb, me); | 97 | ecore_timer_add(atof(arguments), _sleep_timer_cb, me); |
98 | else if (0 == strncmp(buf, "llResetTime(", 12)) | 98 | else if (0 == strcmp(command, "llResetTime")) |
99 | { | 99 | { |
100 | takeScript(me); | 100 | takeScript(me); |
101 | gettimeofday(&me->startTime, NULL); | 101 | gettimeofday(&me->startTime, NULL); |
102 | releaseScript(me); | 102 | releaseScript(me); |
103 | } | 103 | } |
104 | else if (0 == strncmp(buf, "llGetTime(", 10)) | 104 | else if (0 == strcmp(command, "llGetTime")) |
105 | { | 105 | { |
106 | struct timeval now; | 106 | struct timeval now; |
107 | float time = timeDiff(&now, &me->startTime); | 107 | float time = timeDiff(&now, &me->startTime); |
108 | char result[128]; | 108 | char result[128]; |
109 | 109 | ||
110 | snprintf(result, sizeof(result), "return %f", time); | 110 | snprintf(result, sizeof(result), "return(%f)", time); |
111 | send2script(me->SID, result); | 111 | send2script(me->SID, result); |
112 | } | 112 | } |
113 | else if (0 == strncmp(buf, "llGetAndResetTime(", 18)) | 113 | else if (0 == strcmp(command, "llGetAndResetTime")) |
114 | { | 114 | { |
115 | struct timeval now; | 115 | struct timeval now; |
116 | float time = timeDiff(&now, &me->startTime); | 116 | float time = timeDiff(&now, &me->startTime); |
@@ -120,13 +120,13 @@ static boolean send2parser(void *data, Connection *connection, char *SID, char * | |||
120 | // Reset it before doing anything else once the result is known. | 120 | // Reset it before doing anything else once the result is known. |
121 | gettimeofday(&me->startTime, NULL); | 121 | gettimeofday(&me->startTime, NULL); |
122 | releaseScript(me); | 122 | releaseScript(me); |
123 | snprintf(result, sizeof(result), "return %f", time); | 123 | snprintf(result, sizeof(result), "return(%f)", time); |
124 | send2script(me->SID, result); | 124 | send2script(me->SID, result); |
125 | } | 125 | } |
126 | else if (0 == strncmp(buf, "llSetTimerEvent(", 16)) | 126 | else if (0 == strcmp(command, "llSetTimerEvent")) |
127 | { | 127 | { |
128 | takeScript(me); | 128 | takeScript(me); |
129 | me->timerTime = atof(&(buf)[16]); | 129 | me->timerTime = atof(arguments); |
130 | if (0.0 == me->timerTime) | 130 | if (0.0 == me->timerTime) |
131 | { | 131 | { |
132 | if (me->timer) | 132 | if (me->timer) |
@@ -137,14 +137,24 @@ static boolean send2parser(void *data, Connection *connection, char *SID, char * | |||
137 | me->timer = ecore_timer_add(me->timerTime, _timer_timer_cb, me); | 137 | me->timer = ecore_timer_add(me->timerTime, _timer_timer_cb, me); |
138 | releaseScript(me); | 138 | releaseScript(me); |
139 | } | 139 | } |
140 | else if (0 == strncmp(buf, "llSetScriptState(", 17)) | 140 | else if (0 == strcmp(command, "llSetScriptState")) |
141 | { | 141 | { |
142 | script *them; | 142 | script *them; |
143 | char *temp = rindex(arguments, '"'), *ext = NULL; | ||
143 | 144 | ||
144 | if ((them = findThem(ourGlobals, me->fileName, &(buf[18])))) | 145 | if (temp) |
145 | { | 146 | { |
146 | char *temp = rindex(&(buf[18]), ','); | 147 | *temp = '\0'; |
148 | ext = temp + 1; | ||
149 | } | ||
150 | |||
151 | temp = arguments; | ||
152 | if ('"' == temp[0]) | ||
153 | temp = &temp[1]; | ||
147 | 154 | ||
155 | if ((them = findThem(ourGlobals, me->fileName, temp))) | ||
156 | { | ||
157 | temp = rindex(ext, ','); | ||
148 | if (temp) | 158 | if (temp) |
149 | { | 159 | { |
150 | temp++; | 160 | temp++; |
@@ -154,31 +164,39 @@ static boolean send2parser(void *data, Connection *connection, char *SID, char * | |||
154 | send2script(them->SID, "start()"); | 164 | send2script(them->SID, "start()"); |
155 | else | 165 | else |
156 | send2script(them->SID, "stop()"); | 166 | send2script(them->SID, "stop()"); |
157 | // PD("Stopped %s", them->name); | 167 | // PD("Started / stopped %s", them->name); |
158 | } | 168 | } |
159 | else | 169 | else |
160 | PE("Missing script state in llSetScriptState(%s, )", them->name); | 170 | PE("Missing script state in llSetScriptState(%s, )", them->name); |
161 | } | 171 | } |
162 | else | 172 | else |
163 | { | 173 | PE("Can't start / stop script, can't find %s", temp); |
164 | char *temp = rindex(&(buf[18]), '"'); | ||
165 | |||
166 | if (temp) | ||
167 | *temp = '\0'; | ||
168 | PE("Can't stop script, can't find %s", &(buf[18])); | ||
169 | } | ||
170 | } | 174 | } |
171 | else if (0 == strncmp(buf, "llResetOtherScript(", 19)) | 175 | else if (0 == strcmp(command, "llResetOtherScript")) |
172 | { | 176 | { |
173 | script *them; | 177 | script *them; |
178 | char *temp = rindex(arguments, '"') ;//, *ext = NULL; | ||
174 | 179 | ||
175 | if ((them = findThem(ourGlobals, me->fileName, &(buf[20])))) | 180 | if (temp) |
181 | { | ||
182 | *temp = '\0'; | ||
183 | // ext = temp + 1; | ||
184 | } | ||
185 | |||
186 | temp = arguments; | ||
187 | if ('"' == temp[0]) | ||
188 | temp = &temp[1]; | ||
189 | |||
190 | |||
191 | if ((them = findThem(ourGlobals, me->fileName, temp))) | ||
176 | { | 192 | { |
177 | PD("RESETTING OTHER %s", them->name); | 193 | PD("RESETTING OTHER %s", them->name); |
178 | resetScript(them); | 194 | resetScript(them); |
179 | } | 195 | } |
196 | else | ||
197 | PE("Can't reset script, can't find %s", temp); | ||
180 | } | 198 | } |
181 | else if (0 == strncmp(buf, "llResetScript(", 14)) | 199 | else if (0 == strcmp(command, "llResetScript")) |
182 | { | 200 | { |
183 | PD("RESETTING %s", me->name); | 201 | PD("RESETTING %s", me->name); |
184 | resetScript(me); | 202 | resetScript(me); |
@@ -239,38 +257,19 @@ static boolean parser(void *data, Connection *connection, char *SID, char *comma | |||
239 | gameGlobals *ourGlobals = data; | 257 | gameGlobals *ourGlobals = data; |
240 | char buf[PATH_MAX]; | 258 | char buf[PATH_MAX]; |
241 | 259 | ||
242 | //PD("PARSE COMMAND %s - '%s' (%s", SID, command, arguments); | 260 | //PD("PARSE COMMAND %s - %s (%s)", SID, command, arguments); |
243 | if (0 == strcmp(command, "compile")) | 261 | if (0 == strcmp(command, "compile")) |
244 | { | 262 | { |
245 | char *temp; | ||
246 | char *file; | ||
247 | LuaCompiler *compiler; | 263 | LuaCompiler *compiler; |
248 | 264 | ||
249 | strcpy(buf, arguments); | 265 | compiler = createCompiler(SID, arguments, (compileCb) compileLSL, _compileCb); |
250 | temp = buf; | ||
251 | file = temp; | ||
252 | while (')' != temp[0]) | ||
253 | temp++; | ||
254 | temp[0] = '\0'; | ||
255 | |||
256 | compiler = createCompiler(SID, file, (compileCb) compileLSL, _compileCb); | ||
257 | compiler->client = connection; | 266 | compiler->client = connection; |
258 | PI("Compiling script %s", file); | 267 | PI("Compiling script %s", arguments); |
259 | compileScript(compiler, TRUE); | 268 | compileScript(compiler, TRUE); |
260 | } | 269 | } |
261 | else if (0 == strcmp(command, "run")) | 270 | else if (0 == strcmp(command, "run")) |
262 | { | 271 | { |
263 | char *temp; | 272 | script *me = scriptAdd(arguments, SID, send2server, ourGlobals); |
264 | char *file; | ||
265 | script *me; | ||
266 | |||
267 | strcpy(buf, arguments); | ||
268 | temp = buf; | ||
269 | file = temp; | ||
270 | while (')' != temp[0]) | ||
271 | temp++; | ||
272 | temp[0] = '\0'; | ||
273 | me = scriptAdd(file, SID, send2server, ourGlobals); | ||
274 | 273 | ||
275 | me->client = connection; | 274 | me->client = connection; |
276 | eina_hash_add(ourGlobals->names, me->fileName, me); | 275 | eina_hash_add(ourGlobals->names, me->fileName, me); |
@@ -293,10 +292,10 @@ static boolean parser(void *data, Connection *connection, char *SID, char *comma | |||
293 | { | 292 | { |
294 | // TODO - Even after moving the above into the command hash, this bit might still remain, unless script.return() can make it go away. | 293 | // TODO - Even after moving the above into the command hash, this bit might still remain, unless script.return() can make it go away. |
295 | // Though perhaps the "else" part stays? | 294 | // Though perhaps the "else" part stays? |
296 | if (0 == strcmp("return", command)) | 295 | // if (0 == strcmp("return", command)) |
297 | snprintf(buf, sizeof(buf), "%s %s", command, arguments); | 296 | // snprintf(buf, sizeof(buf), "%s(%s)", command, arguments); |
298 | else | 297 | // else |
299 | snprintf(buf, sizeof(buf), "%s(%s", command, arguments); | 298 | snprintf(buf, sizeof(buf), "%s(%s)", command, arguments); |
300 | //PD("Sending -> script %s : %s", SID, buf); | 299 | //PD("Sending -> script %s : %s", SID, buf); |
301 | send2script(SID, buf); | 300 | send2script(SID, buf); |
302 | } | 301 | } |