-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathsandboxScript.lua
More file actions
81 lines (63 loc) · 2.47 KB
/
sandboxScript.lua
File metadata and controls
81 lines (63 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
if _DEVMODE then addLog(430, "Developer Mode is active") end
sim = require('sim-2')
pythonFailWarnOnly = true -- error msg can be read via sim.getNamedBoolParam("pythonSandboxInitFailMsg")
base16 = require('base16')
base64 = require('base64')
require('base-ce')
local l = auxFunc('getfiles', sim.getStringProperty(sim.handle_app, 'luaPath'), '*-ce', 'lua')
for i = 1, #l, 1 do require(string.gsub(l[i], "%.lua$", "")) end
--_setupLazyLoaders() -- because those were cleared out by our explicit requires
function s_init()
sim.app:addLog("Simulator launched, welcome! ")
if sim.getIntProperty(sim.handle_app, 'headlessMode') == 0 then
require('simURLDrop')
if sim.getBoolProperty(sim.handle_app, 'signal.pythonSandboxInitFailed', {noError = true}) ~= true then
require('pythonLuaSetupAssistant')
end
end
end
function s_cleanup()
sim.app:addLog("Leaving...")
end
function s_beforeSimulation()
sim.app:addLog("Simulation started.")
end
function s_afterSimulation()
sim.app:addLog("Simulation stopped.")
___m = nil
end
function s_sensing()
local s = sim.getSimulationState()
if s == sim.simulation_advancing_lastbeforestop and not ___m then
sim.app:addLog("Simulation stopping...")
___m = true
end
end
function s_suspend()
sim.app:addLog("Simulation suspended.")
end
function s_resume()
sim.app:addLog("Simulation resumed.")
end
function restart()
__restart = true
end
function s_nonSimulation()
if __restart then return {cmd = 'restart'} end
end
function s_actuation()
if __restart then return {cmd = 'restart'} end
end
function s_suspended()
if __restart then return {cmd = 'restart'} end
end
sim.self:registerFunctionHook('sysCall_init', 's_init', false) -- hook on *before* init is incompatible with implicit module load...
sim.self:registerFunctionHook('sysCall_cleanup', 's_cleanup', false)
sim.self:registerFunctionHook('sysCall_beforeSimulation', 's_beforeSimulation', false)
sim.self:registerFunctionHook('sysCall_afterSimulation', 's_afterSimulation', false)
sim.self:registerFunctionHook('sysCall_sensing', 's_sensing', false)
sim.self:registerFunctionHook('sysCall_suspend', 's_suspend', false)
sim.self:registerFunctionHook('sysCall_resume', 's_resume', false)
sim.self:registerFunctionHook('sysCall_nonSimulation', 's_nonSimulation', false)
sim.self:registerFunctionHook('sysCall_actuation', 's_actuation', false)
sim.self:registerFunctionHook('sysCall_suspended', 's_suspended', false)