diff options
author | David Walter Seikel | 2016-01-18 23:49:31 +1000 |
---|---|---|
committer | David Walter Seikel | 2016-01-18 23:49:31 +1000 |
commit | 8999fc182e7cd0b5f5c00c4797760e17c339fc97 (patch) | |
tree | ae54b5c186ff2c0808b8ad4e4c8fb072b799c148 /lib | |
parent | Added a vision statement. lol (diff) | |
download | SledjHamr-8999fc182e7cd0b5f5c00c4797760e17c339fc97.zip SledjHamr-8999fc182e7cd0b5f5c00c4797760e17c339fc97.tar.gz SledjHamr-8999fc182e7cd0b5f5c00c4797760e17c339fc97.tar.bz2 SledjHamr-8999fc182e7cd0b5f5c00c4797760e17c339fc97.tar.xz |
Fix up events.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/LSL.lua | 90 |
1 files changed, 47 insertions, 43 deletions
diff --git a/lib/LSL.lua b/lib/LSL.lua index f4c7fd4..58620e7 100644 --- a/lib/LSL.lua +++ b/lib/LSL.lua | |||
@@ -122,41 +122,41 @@ function events.detectsClear() | |||
122 | detectedVels = {} | 122 | detectedVels = {} |
123 | end | 123 | end |
124 | 124 | ||
125 | function events.at_rot_target(tnum, targetrot, ourrot) if nil ~= currentState.at_rot_target then currentState.at_rot_target(tnum, targetrot, ourrot) end events.detectsClear() end | 125 | function events.at_rot_target(tnum, targetrot, ourrot) if "function" == type(currentState.at_rot_target) then currentState.at_rot_target(tnum, targetrot, ourrot) end events.detectsClear() end |
126 | function events.at_target(tnum, targetpos, ourpos) if nil ~= currentState.at_target then currentState.at_target(tnum, targetpos, ourpos) end events.detectsClear() end | 126 | function events.at_target(tnum, targetpos, ourpos) if "function" == type(currentState.at_target) then currentState.at_target(tnum, targetpos, ourpos) end events.detectsClear() end |
127 | function events.attach(id) if nil ~= currentState.attach then currentState.attach(id) end events.detectsClear() end | 127 | function events.attach(id) if "function" == type(currentState.attach) then currentState.attach(id) end events.detectsClear() end |
128 | function events.changed(change) if nil ~= currentState.changed then currentState.changed(change) end events.detectsClear() end | 128 | function events.changed(change) if "function" == type(currentState.changed) then currentState.changed(change) end events.detectsClear() end |
129 | function events.collision_start(num_detected) if nil ~= currentState.collision_start then currentState.collision_start(num_detected) end events.detectsClear() end | 129 | function events.collision_start(num_detected) if "function" == type(currentState.collision_start) then currentState.collision_start(num_detected) end events.detectsClear() end |
130 | function events.collision(num_detected) if nil ~= currentState.collision then currentState.collision(num_detected) end events.detectsClear() end | 130 | function events.collision(num_detected) if "function" == type(currentState.collision) then currentState.collision(num_detected) end events.detectsClear() end |
131 | function events.collision_end(num_detected) if nil ~= currentState.collision_end then currentState.collision_end(num_detected) end events.detectsClear() end | 131 | function events.collision_end(num_detected) if "function" == type(currentState.collision_end) then currentState.collision_end(num_detected) end events.detectsClear() end |
132 | function events.control(id, held, changed) if nil ~= currentState.control then currentState.control(id, held, changed) end events.detectsClear() end | 132 | function events.control(id, held, changed) if "function" == type(currentState.control) then currentState.control(id, held, changed) end events.detectsClear() end |
133 | function events.dataserver(queryid, data) if nil ~= currentState.dataserver then currentState.dataserver(queryid, data) end events.detectsClear() end | 133 | function events.dataserver(queryid, data) if "function" == type(currentState.dataserver) then currentState.dataserver(queryid, data) end events.detectsClear() end |
134 | function events.email(Time, address, subj, message, num_left) if nil ~= currentState.email then currentState.email(Time, address, subj, message, num_left) end events.detectsClear() end | 134 | function events.email(Time, address, subj, message, num_left) if "function" == type(currentState.email) then currentState.email(Time, address, subj, message, num_left) end events.detectsClear() end |
135 | function events.http_request(request_id, status, metadata, body) if nil ~= currentState.http_request then currentState.http_request(request_id, status, metadata, body) end events.detectsClear() end | 135 | function events.http_request(request_id, status, metadata, body) if "function" == type(currentState.http_request) then currentState.http_request(request_id, status, metadata, body) end events.detectsClear() end |
136 | function events.http_response(request_id, status, metadata, body) if nil ~= currentState.http_response then currentState.http_response(request_id, status, metadata, body) end events.detectsClear() end | 136 | function events.http_response(request_id, status, metadata, body) if "function" == type(currentState.http_response) then currentState.http_response(request_id, status, metadata, body) end events.detectsClear() end |
137 | function events.land_collision_start(pos) if nil ~= currentState.land_collision_start then currentState.land_collision_start(pos) end events.detectsClear() end | 137 | function events.land_collision_start(pos) if "function" == type(currentState.land_collision_start) then currentState.land_collision_start(pos) end events.detectsClear() end |
138 | function events.land_collision(pos) if nil ~= currentState.land_collision then currentState.land_collision(pos) end events.detectsClear() end | 138 | function events.land_collision(pos) if "function" == type(currentState.land_collision) then currentState.land_collision(pos) end events.detectsClear() end |
139 | function events.land_collision_end(pos) if nil ~= currentState.land_collision_end then currentState.land_collision_end(pos) end events.detectsClear() end | 139 | function events.land_collision_end(pos) if "function" == type(currentState.land_collision_end) then currentState.land_collision_end(pos) end events.detectsClear() end |
140 | function events.link_message(sender_num, num, str, id) if nil ~= currentState.link_message then currentState.link_message(sender_num, num, str, id) end events.detectsClear() end | 140 | function events.link_message(sender_num, num, str, id) if "function" == type(currentState.link_message) then currentState.link_message(sender_num, num, str, id) end events.detectsClear() end |
141 | function events.listen(channel, name, id, message) if nil ~= currentState.listen then currentState.listen(channel, name, id, message) end events.detectsClear() end | 141 | function events.listen(channel, name, id, message) if "function" == type(currentState.listen) then currentState.listen(channel, name, id, message) end events.detectsClear() end |
142 | function events.money(id, amount) if nil ~= currentState.money then currentState.money(id, amount) end events.detectsClear() end | 142 | function events.money(id, amount) if "function" == type(currentState.money) then currentState.money(id, amount) end events.detectsClear() end |
143 | function events.moving_start() if nil ~= currentState.moving_start then currentState.moving_start() end events.detectsClear() end | 143 | function events.moving_start() if "function" == type(currentState.moving_start) then currentState.moving_start() end events.detectsClear() end |
144 | function events.moving_end() if nil ~= currentState.moving_end then currentState.moving_end() end events.detectsClear() end | 144 | function events.moving_end() if "function" == type(currentState.moving_end) then currentState.moving_end() end events.detectsClear() end |
145 | function events.no_sensor() if nil ~= currentState.no_sensor then currentState.no_sensor() end events.detectsClear() end | 145 | function events.no_sensor() if "function" == type(currentState.no_sensor) then currentState.no_sensor() end events.detectsClear() end |
146 | function events.not_at_rot_target() if nil ~= currentState.not_at_rot_target then currentState.not_at_rot_target() end events.detectsClear() end | 146 | function events.not_at_rot_target() if "function" == type(currentState.not_at_rot_target) then currentState.not_at_rot_target() end events.detectsClear() end |
147 | function events.not_at_target() if nil ~= currentState.not_at_target then currentState.not_at_target() end events.detectsClear() end | 147 | function events.not_at_target() if "function" == type(currentState.not_at_target) then currentState.not_at_target() end events.detectsClear() end |
148 | function events.object_rez(id) if nil ~= currentState.object_rez then currentState.object_rez() end events.detectsClear() end | 148 | function events.object_rez(id) if "function" == type(currentState.object_rez) then currentState.object_rez() end events.detectsClear() end |
149 | function events.on_rez(start_param) if nil ~= currentState.on_rezz then currentState.on_rez(start_param) end events.detectsClear() end | 149 | function events.on_rez(start_param) if "function" == type(currentState.on_rezz) then currentState.on_rez(start_param) end events.detectsClear() end |
150 | function events.remote_data(event_type, channel, message_id, sender, idata, sdata) if nil ~= currentState.remote_data then currentState.remote_data(event_type, channel, message_id, sender, idata, sdata) end events.detectsClear() end | 150 | function events.remote_data(event_type, channel, message_id, sender, idata, sdata) if "function" == type(currentState.remote_data) then currentState.remote_data(event_type, channel, message_id, sender, idata, sdata) end events.detectsClear() end |
151 | function events.run_time_permissions(perm) if nil ~= currentState.run_time_permisions then currentState.run_time_permissions(perm) end events.detectsClear() end | 151 | function events.run_time_permissions(perm) if "function" == type(currentState.run_time_permisions) then currentState.run_time_permissions(perm) end events.detectsClear() end |
152 | function events.sensor(num_detected) if nil ~= currentState.sensor then currentState.sensor(num_detected) end events.detectsClear() end | 152 | function events.sensor(num_detected) if "function" == type(currentState.sensor) then currentState.sensor(num_detected) end events.detectsClear() end |
153 | function events.state_entry() if nil ~= currentState.state_entry then currentState.state_entry() end events.detectsClear() end | 153 | function events.state_entry() if "function" == type(currentState.state_entry) then currentState.state_entry() end events.detectsClear() end |
154 | function events.state_exit() if nil ~= currentState.state_exit then currentState.state_exit() end events.detectsClear() end | 154 | function events.state_exit() if "function" == type(currentState.state_exit) then currentState.state_exit() end events.detectsClear() end |
155 | function events.timer() if nil ~= currentState.timer then currentState.timer() end events.detectsClear() end | 155 | function events.timer() if "function" == type(currentState.timer) then currentState.timer() end events.detectsClear() end |
156 | function events.touch_start(num_detected) if nil ~= currentState.touch_start then currentState.touch_start(num_detected) end events.detectsClear() end | 156 | function events.touch_start(num_detected) if "function" == type(currentState.touch_start) then currentState.touch_start(num_detected) end events.detectsClear() end |
157 | function events.touch(num_detected) if nil ~= currentState.touch then currentState.touch(num_detected) end events.detectsClear() end | 157 | function events.touch(num_detected) if "function" == type(currentState.touch) then currentState.touch(num_detected) end events.detectsClear() end |
158 | function events.touch_end(num_detected) if nil ~= currentState.touch_end then currentState.touch_end(num_detected) end events.detectsClear() end | 158 | function events.touch_end(num_detected) if "function" == type(currentState.touch_end) then currentState.touch_end(num_detected) end events.detectsClear() end |
159 | function events.transaction_result(id, success, data) if nil ~= currentState.transaction_result then currentState.transaction_result(id, success, data) end events.detectsClear() end | 159 | function events.transaction_result(id, success, data) if "function" == type(currentState.transaction_result) then currentState.transaction_result(id, success, data) end events.detectsClear() end |
160 | 160 | ||
161 | 161 | ||
162 | -- LSL function and constant creation stuff. | 162 | -- LSL function and constant creation stuff. |
@@ -2010,17 +2010,21 @@ function waitAndProcess(returnWanted, name, ...) | |||
2010 | else | 2010 | else |
2011 | local 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 | 2011 | local 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 |
2012 | if nil == result then | 2012 | if nil == result then |
2013 | msg("Not a valid " .. Type .. ": " .. message .. " ERROR MESSAGE: " .. errorMsg) | 2013 | local text = "Not a valid " .. Type .. ": " .. message .. " ERROR MESSAGE: " .. errorMsg |
2014 | -- print("Not a valid " .. Type .. ": " .. message .. " ERROR MESSAGE: " .. errorMsg) | 2014 | msg(text) |
2015 | print(text) | ||
2015 | else | 2016 | else |
2016 | -- Set the functions environment to ours, for the protection of the script, coz loadstring sets it to the global environment instead. | 2017 | -- Set the functions environment to ours, for the protection of the script, coz loadstring sets it to the global environment. |
2017 | -- 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. | 2018 | -- On the other hand, we will need the global environment when we call event handlers. |
2018 | -- Meh, seems to be working fine as it is. Or not. | 2019 | if "event" ~= Type then |
2019 | setfenv(result, getfenv(1)) | 2020 | setfenv(result, getfenv(1)) |
2021 | end | ||
2022 | |||
2020 | local status, result1 = pcall(result) | 2023 | local status, result1 = pcall(result) |
2021 | if not status then | 2024 | if not status then |
2022 | msg("Error from " .. Type .. ": " .. message .. " ERROR MESSAGE: " .. result1) | 2025 | local text = "Error from " .. Type .. ": " .. message .. " ERROR MESSAGE: " .. result1 |
2023 | print("Error from " .. Type .. ": " .. message .. " ERROR MESSAGE: " .. result1) | 2026 | msg(text) |
2027 | print(text) | ||
2024 | elseif result1 then | 2028 | elseif result1 then |
2025 | -- Check if we are waiting for a return, and got it. | 2029 | -- Check if we are waiting for a return, and got it. |
2026 | if returnWanted and string.match(message, "^return ") then | 2030 | if returnWanted and string.match(message, "^return ") then |