diff options
author | David Walter Seikel | 2012-02-08 17:14:06 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-02-08 17:14:06 +1000 |
commit | de674bd5cd29e1a640923fee6fecdc525692be78 (patch) | |
tree | 01560ebbe568c90fbf7f30f55db7bc819720c97d | |
parent | Cleaning up some comments. (diff) | |
download | SledjHamr-de674bd5cd29e1a640923fee6fecdc525692be78.zip SledjHamr-de674bd5cd29e1a640923fee6fecdc525692be78.tar.gz SledjHamr-de674bd5cd29e1a640923fee6fecdc525692be78.tar.bz2 SledjHamr-de674bd5cd29e1a640923fee6fecdc525692be78.tar.xz |
New Lua logging function for testing, and use it.
-rw-r--r-- | LuaSL/src/LSL.lua | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/LuaSL/src/LSL.lua b/LuaSL/src/LSL.lua index 1ec3fa1..c4fae25 100644 --- a/LuaSL/src/LSL.lua +++ b/LuaSL/src/LSL.lua | |||
@@ -29,6 +29,7 @@ upvalue--either way is a bit more efficient and less error prone. | |||
29 | -- http://www.lua.org/pil/15.5.html the last part about autoloading functions might be useful. | 29 | -- http://www.lua.org/pil/15.5.html the last part about autoloading functions might be useful. |
30 | 30 | ||
31 | local LSL = {}; | 31 | local LSL = {}; |
32 | local SID = ""; | ||
32 | 33 | ||
33 | 34 | ||
34 | -- Debugging aids | 35 | -- Debugging aids |
@@ -55,6 +56,9 @@ function print_table(table, space) | |||
55 | end | 56 | end |
56 | end | 57 | end |
57 | 58 | ||
59 | function msg(...) | ||
60 | print(SID, ...) -- The comma adds a tab, fancy that. B-) | ||
61 | end | ||
58 | 62 | ||
59 | -- LSL constants. | 63 | -- LSL constants. |
60 | 64 | ||
@@ -261,12 +265,12 @@ function LSL.llDie() end; | |||
261 | function --[[integer]] LSL.llGetFreeMemory() return 0 end; | 265 | function --[[integer]] LSL.llGetFreeMemory() return 0 end; |
262 | function --[[string]] LSL.llGetScriptName() return "" end; | 266 | function --[[string]] LSL.llGetScriptName() return "" end; |
263 | function --[[float]] LSL.llGetTime() return 0.0 end; | 267 | function --[[float]] LSL.llGetTime() return 0.0 end; |
264 | function LSL.llResetOtherScript(--[[string]] name) print("llResetOtherScript(" .. name .. ")") end; | 268 | function LSL.llResetOtherScript(--[[string]] name) msg("llResetOtherScript(" .. name .. ")") end; |
265 | function LSL.llResetScript() end; | 269 | function LSL.llResetScript() end; |
266 | function LSL.llResetTime() end; | 270 | function LSL.llResetTime() end; |
267 | function LSL.llSetScriptState(--[[string]] name,--[[integer]] running) print("llSetScriptState(" .. name .. "," .. running .. ")") end; | 271 | function LSL.llSetScriptState(--[[string]] name,--[[integer]] running) msg("llSetScriptState(" .. name .. "," .. running .. ")") end; |
268 | function LSL.llSetTimerEvent(--[[float]] seconds) end; | 272 | function LSL.llSetTimerEvent(--[[float]] seconds) end; |
269 | function LSL.llSleep(--[[float]] seconds) print("llSleep(" .. seconds .. ")") end; | 273 | function LSL.llSleep(--[[float]] seconds) msg("llSleep(" .. seconds .. ")") end; |
270 | 274 | ||
271 | function LSL.llPlaySound(--[[string]] name,--[[float]] volume) end; | 275 | function LSL.llPlaySound(--[[string]] name,--[[float]] volume) end; |
272 | function LSL.llRezObject(--[[string]] name, --[[vector]] position, --[[vector]] velocity, --[[rotation]] rot,--[[integer]] channel) end; | 276 | function LSL.llRezObject(--[[string]] name, --[[vector]] position, --[[vector]] velocity, --[[rotation]] rot,--[[integer]] channel) end; |
@@ -302,10 +306,10 @@ function LSL.llUnSit(--[[key]] avatar) end; | |||
302 | function LSL.llDialog(--[[key]] avatar, --[[string]] caption, --[[list]] arseBackwardsMenu,--[[integer]] channel) end; | 306 | function LSL.llDialog(--[[key]] avatar, --[[string]] caption, --[[list]] arseBackwardsMenu,--[[integer]] channel) end; |
303 | function --[[integer]] LSL.llListen(--[[integer]] channel, --[[string]] name, --[[key]] id, --[[string]] msg) return 0 end; | 307 | function --[[integer]] LSL.llListen(--[[integer]] channel, --[[string]] name, --[[key]] id, --[[string]] msg) return 0 end; |
304 | function LSL.llListenRemove(--[[integer]] handle) end; | 308 | function LSL.llListenRemove(--[[integer]] handle) end; |
305 | function LSL.llOwnerSay(--[[string]] text) print("Owner say: " .. text); end; | 309 | function LSL.llOwnerSay(--[[string]] text) msg("Owner say: " .. text); end; |
306 | function LSL.llSay(--[[integer]] channel, --[[string]] text) print("Channel " .. channel .. " say: " .. text); end; | 310 | function LSL.llSay(--[[integer]] channel, --[[string]] text) msg("Channel " .. channel .. " say: " .. text); end; |
307 | function LSL.llShout(--[[integer]] channel, --[[string]] text) print("Channel " .. channel .. " shout: " .. text); end; | 311 | function LSL.llShout(--[[integer]] channel, --[[string]] text) msg("Channel " .. channel .. " shout: " .. text); end; |
308 | function LSL.llWhisper(--[[integer]] channel, --[[string]] text) print("Channel " .. channel .. " whisper: " .. text); end; | 312 | function LSL.llWhisper(--[[integer]] channel, --[[string]] text) msg("Channel " .. channel .. " whisper: " .. text); end; |
309 | 313 | ||
310 | function LSL.llMessageLinked(--[[integer]] link,--[[integer]] num, --[[string]] text, --[[key]] aKey) end; | 314 | function LSL.llMessageLinked(--[[integer]] link,--[[integer]] num, --[[string]] text, --[[key]] aKey) end; |
311 | 315 | ||
@@ -500,13 +504,15 @@ function LSL.stateChange(x) | |||
500 | end | 504 | end |
501 | end; | 505 | end; |
502 | 506 | ||
503 | function LSL.mainLoop(SID, x) | 507 | function LSL.mainLoop(ourSID, x) |
504 | local sid = SID .. ".events" | 508 | local sid = ourSID .. ".events" |
505 | local status, errorMsg = luaproc.newchannel(sid) | 509 | local status, errorMsg = luaproc.newchannel(sid) |
506 | local result | 510 | local result |
507 | 511 | ||
512 | SID = ourSID | ||
513 | |||
508 | if not status then | 514 | if not status then |
509 | print("Can't open the luaproc channel " .. sid .. " ERROR MESSAGE: " .. errorMsg) | 515 | msg("Can't open the luaproc channel " .. sid .. " ERROR MESSAGE: " .. errorMsg) |
510 | return | 516 | return |
511 | end | 517 | end |
512 | 518 | ||
@@ -524,18 +530,18 @@ function LSL.mainLoop(SID, x) | |||
524 | else | 530 | else |
525 | result, errorMsg = loadstring(message) -- "The environment of the returned function is the global environment." Though normally, a function inherits it's environment from the function creating it. Which is what we want. lol | 531 | result, errorMsg = loadstring(message) -- "The environment of the returned function is the global environment." Though normally, a function inherits it's environment from the function creating it. Which is what we want. lol |
526 | if nil == result then | 532 | if nil == result then |
527 | print("Not a valid event: " .. message .. " ERROR MESSAGE: " .. errorMsg) | 533 | msg("Not a valid event: " .. message .. " ERROR MESSAGE: " .. errorMsg) |
528 | else | 534 | else |
529 | -- Set the functions environment to ours, for the protection of the script, coz loadstring sets it to the global environment instead. | 535 | -- Set the functions environment to ours, for the protection of the script, coz loadstring sets it to the global environment instead. |
530 | -- TODO - On the other hand, we will need the global environment when we call event handlers. So we should probably stash it around here somewhere. | 536 | -- TODO - On the other hand, we will need the global environment when we call event handlers. So we should probably stash it around here somewhere. |
531 | setfenv(result, getfenv(1)) | 537 | setfenv(result, getfenv(1)) |
532 | status, result = pcall(result) | 538 | status, result = pcall(result) |
533 | if not status then | 539 | if not status then |
534 | print("Error from event: " .. message .. " ERROR MESSAGE: " .. result) | 540 | msg("Error from event: " .. message .. " ERROR MESSAGE: " .. result) |
535 | elseif result then | 541 | elseif result then |
536 | status, errorMsg = luaproc.send(sid, result) | 542 | status, errorMsg = luaproc.send(sid, result) |
537 | if not status then | 543 | if not status then |
538 | print("Error sending results from event: " .. message .. " ERROR MESSAGE: " .. errorMsg) | 544 | msg("Error sending results from event: " .. message .. " ERROR MESSAGE: " .. errorMsg) |
539 | end | 545 | end |
540 | end | 546 | end |
541 | end | 547 | end |