aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDavid Walter Seikel2012-02-08 17:14:06 +1000
committerDavid Walter Seikel2012-02-08 17:14:06 +1000
commitde674bd5cd29e1a640923fee6fecdc525692be78 (patch)
tree01560ebbe568c90fbf7f30f55db7bc819720c97d
parentCleaning up some comments. (diff)
downloadSledjHamr-de674bd5cd29e1a640923fee6fecdc525692be78.zip
SledjHamr-de674bd5cd29e1a640923fee6fecdc525692be78.tar.gz
SledjHamr-de674bd5cd29e1a640923fee6fecdc525692be78.tar.bz2
SledjHamr-de674bd5cd29e1a640923fee6fecdc525692be78.tar.xz
New Lua logging function for testing, and use it.
Diffstat (limited to '')
-rw-r--r--LuaSL/src/LSL.lua32
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
31local LSL = {}; 31local LSL = {};
32local SID = "";
32 33
33 34
34-- Debugging aids 35-- Debugging aids
@@ -55,6 +56,9 @@ function print_table(table, space)
55 end 56 end
56end 57end
57 58
59function msg(...)
60 print(SID, ...) -- The comma adds a tab, fancy that. B-)
61end
58 62
59-- LSL constants. 63-- LSL constants.
60 64
@@ -261,12 +265,12 @@ function LSL.llDie() end;
261function --[[integer]] LSL.llGetFreeMemory() return 0 end; 265function --[[integer]] LSL.llGetFreeMemory() return 0 end;
262function --[[string]] LSL.llGetScriptName() return "" end; 266function --[[string]] LSL.llGetScriptName() return "" end;
263function --[[float]] LSL.llGetTime() return 0.0 end; 267function --[[float]] LSL.llGetTime() return 0.0 end;
264function LSL.llResetOtherScript(--[[string]] name) print("llResetOtherScript(" .. name .. ")") end; 268function LSL.llResetOtherScript(--[[string]] name) msg("llResetOtherScript(" .. name .. ")") end;
265function LSL.llResetScript() end; 269function LSL.llResetScript() end;
266function LSL.llResetTime() end; 270function LSL.llResetTime() end;
267function LSL.llSetScriptState(--[[string]] name,--[[integer]] running) print("llSetScriptState(" .. name .. "," .. running .. ")") end; 271function LSL.llSetScriptState(--[[string]] name,--[[integer]] running) msg("llSetScriptState(" .. name .. "," .. running .. ")") end;
268function LSL.llSetTimerEvent(--[[float]] seconds) end; 272function LSL.llSetTimerEvent(--[[float]] seconds) end;
269function LSL.llSleep(--[[float]] seconds) print("llSleep(" .. seconds .. ")") end; 273function LSL.llSleep(--[[float]] seconds) msg("llSleep(" .. seconds .. ")") end;
270 274
271function LSL.llPlaySound(--[[string]] name,--[[float]] volume) end; 275function LSL.llPlaySound(--[[string]] name,--[[float]] volume) end;
272function LSL.llRezObject(--[[string]] name, --[[vector]] position, --[[vector]] velocity, --[[rotation]] rot,--[[integer]] channel) end; 276function LSL.llRezObject(--[[string]] name, --[[vector]] position, --[[vector]] velocity, --[[rotation]] rot,--[[integer]] channel) end;
@@ -302,10 +306,10 @@ function LSL.llUnSit(--[[key]] avatar) end;
302function LSL.llDialog(--[[key]] avatar, --[[string]] caption, --[[list]] arseBackwardsMenu,--[[integer]] channel) end; 306function LSL.llDialog(--[[key]] avatar, --[[string]] caption, --[[list]] arseBackwardsMenu,--[[integer]] channel) end;
303function --[[integer]] LSL.llListen(--[[integer]] channel, --[[string]] name, --[[key]] id, --[[string]] msg) return 0 end; 307function --[[integer]] LSL.llListen(--[[integer]] channel, --[[string]] name, --[[key]] id, --[[string]] msg) return 0 end;
304function LSL.llListenRemove(--[[integer]] handle) end; 308function LSL.llListenRemove(--[[integer]] handle) end;
305function LSL.llOwnerSay(--[[string]] text) print("Owner say: " .. text); end; 309function LSL.llOwnerSay(--[[string]] text) msg("Owner say: " .. text); end;
306function LSL.llSay(--[[integer]] channel, --[[string]] text) print("Channel " .. channel .. " say: " .. text); end; 310function LSL.llSay(--[[integer]] channel, --[[string]] text) msg("Channel " .. channel .. " say: " .. text); end;
307function LSL.llShout(--[[integer]] channel, --[[string]] text) print("Channel " .. channel .. " shout: " .. text); end; 311function LSL.llShout(--[[integer]] channel, --[[string]] text) msg("Channel " .. channel .. " shout: " .. text); end;
308function LSL.llWhisper(--[[integer]] channel, --[[string]] text) print("Channel " .. channel .. " whisper: " .. text); end; 312function LSL.llWhisper(--[[integer]] channel, --[[string]] text) msg("Channel " .. channel .. " whisper: " .. text); end;
309 313
310function LSL.llMessageLinked(--[[integer]] link,--[[integer]] num, --[[string]] text, --[[key]] aKey) end; 314function 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
501end; 505end;
502 506
503function LSL.mainLoop(SID, x) 507function 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