Skip to content

Instantly share code, notes, and snippets.

@d-lua-stuff
Last active September 4, 2020 10:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d-lua-stuff/a23df77771aba574ca91f86888a2a69c to your computer and use it in GitHub Desktop.
Save d-lua-stuff/a23df77771aba574ca91f86888a2a69c to your computer and use it in GitHub Desktop.
{
"slots":{
"0":{
"name":"screen",
"type":{
"methods":[],
"events":[]
},
"_elementType":"screen"
},
"1":{
"name":"slot2",
"type":{
"methods":[],
"events":[]
}
},
"2":{
"name":"slot3",
"type":{
"methods":[],
"events":[]
}
},
"3":{
"name":"slot4",
"type":{
"methods":[],
"events":[]
}
},
"4":{
"name":"slot5",
"type":{
"methods":[],
"events":[]
}
},
"5":{
"name":"slot6",
"type":{
"methods":[],
"events":[]
}
},
"6":{
"name":"slot7",
"type":{
"methods":[],
"events":[]
}
},
"7":{
"name":"slot8",
"type":{
"methods":[],
"events":[]
}
},
"8":{
"name":"slot9",
"type":{
"methods":[],
"events":[]
}
},
"9":{
"name":"slot10",
"type":{
"methods":[],
"events":[]
}
},
"-1":{
"name":"unit",
"type":{
"methods":[],
"events":[]
},
"_elementType":"control"
},
"-2":{
"name":"system",
"type":{
"methods":[],
"events":[]
},
"_elementType":"system"
},
"-3":{
"name":"library",
"type":{
"methods":[],
"events":[]
},
"_elementType":"library"
}
},
"handlers":[{
"key":"0",
"filter":{
"slotKey":0,
"signature":"mouseDown(x,y)",
"args":[{
"variable":"*"
},{
"variable":"*"
}]
},
"code":"if not __wrap_lua__stopped and script.onMouseDown then\n local ok, message = xpcall(script.onMouseDown,__wrap_lua__traceback,x,y,screen)\n if not ok then __wrap_lua__error(message) end\nend"
},{
"key":"1",
"filter":{
"slotKey":0,
"signature":"mouseUp(x,y)",
"args":[{
"variable":"*"
},{
"variable":"*"
}]
},
"code":"if not __wrap_lua__stopped and script.onMouseUp then\n local ok, message = xpcall(script.onMouseUp,__wrap_lua__traceback,x,y,screen)\n if not ok then __wrap_lua__error(message) end\nend"
},{
"key":"2",
"filter":{
"slotKey":-1,
"signature":"start()",
"args":[]
},
"code":"-- error handling code added by wrap.lua\n__wrap_lua__stopped = false\n__wrap_lua__stopOnError = false\n__wrap_lua__rethrowErrorAlways = false\n__wrap_lua__rethrowErrorIfStopped = true\n__wrap_lua__printError = true\n__wrap_lua__showErrorOnScreens = true\n\nfunction __wrap_lua__error (message)\n if __wrap_lua__stopped then return end\n\n -- make the traceback more readable and escape HTML syntax characters\n message = tostring(message):gsub('\"%-%- |STDERROR%-EVENTHANDLER[^\"]*\"', 'chunk'):gsub(\"&\", \"&amp;\"):gsub(\"<\", \"&lt;\"):gsub(\">\", \"&gt;\")\n\n local unit = unit or self or {}\n\n if __wrap_lua__showErrorOnScreens then\n for _, value in pairs(unit) do\n if type(value) == \"table\" and value.setCenteredText and value.setHTML then -- value is a screen\n if message:match(\"\\n\") then\n value.setHTML([[\n<pre style=\"color: white; background-color: black; font-family: Consolas,monospace; font-size: 4vh; white-space: pre-wrap; margin: 1em\">\nError: ]] .. message .. [[\n</pre>]])\n else\n value.setCenteredText(message)\n end\n end\n end\n end\n\n if __wrap_lua__printError and system and system.print then\n system.print(\"Error: \" .. message:gsub(\"\\n\", \"<br>\"))\n end\n\n if __wrap_lua__stopOnError then\n __wrap_lua__stopped = true\n end\n\n if __wrap_lua__stopped and unit and unit.exit then\n unit.exit()\n end\n\n if __wrap_lua__rethrowErrorAlways or (__wrap_lua__stopped and __wrap_lua__rethrowErrorIfStopped) then\n error(message)\n end\nend\n\n-- in case traceback is removed or renamed\n__wrap_lua__traceback = traceback or (debug and debug.traceback) or function (arg1, arg2) return arg2 or arg1 end\n\nlocal ok, message = xpcall(function ()\n\n-- script code\n\n-- Define a global script object with event handlers\nscript = {}\n\nfunction script.onStart ()\n -- Display some text\n screen.setCenteredText(\"script started\")\n\n -- Create some timers to show that the script is working\n unit.setTimer(\"a\", 2) -- timer id \"a\", ticks every 2 seconds\n unit.setTimer(\"b\", 3) -- timer id \"b\", ticks every 3 seconds\nend\n\nfunction script.onStop ()\n screen.setCenteredText(\"script stopped\")\nend\n\nfunction script.onActionStart (actionName)\n screen.setCenteredText(actionName .. \" key pressed\")\nend\n\nfunction script.onActionStop (actionName)\n screen.setCenteredText(actionName .. \" key released\")\nend\n\nfunction script.onTick (timerId)\n screen.setCenteredText(\"timer \" .. timerId .. \" ticked\")\nend\n\n-- Other events that are available by default:\n-- * onActionLoop(actionName): action key is held\n-- * onUpdate(): executed once per frame\n-- * onFlush(): executed 60 times per second, for physics calculations only; setEngineCommand must be called from here\n\n-- Slot events are available if slot type is set with the --slot command line option.\nfunction script.onMouseDown (x, y)\n screen.setCenteredText(\"mouse down: x=\" .. x .. \" , y=\" .. y)\nend\n\n-- Call the start event handler\n-- Alternatively, initialization code can be placed anywhere in this file.\n-- The only requirement is that there is a global \"script\" object with event handlers\nscript.onStart()\n\n\n-- error handling code added by wrap.lua\nend, __wrap_lua__traceback)\nif not ok then\n __wrap_lua__error(message)\n if not script then script = {} end\nend"
},{
"key":"3",
"filter":{
"slotKey":-1,
"signature":"stop()",
"args":[]
},
"code":"if not __wrap_lua__stopped and script.onStop then\n local ok, message = xpcall(script.onStop,__wrap_lua__traceback,unit)\n if not ok then __wrap_lua__error(message) end\nend"
},{
"key":"4",
"filter":{
"slotKey":-1,
"signature":"tick(timerId)",
"args":[{
"variable":"*"
}]
},
"code":"if not __wrap_lua__stopped and script.onTick then\n local ok, message = xpcall(script.onTick,__wrap_lua__traceback,timerId,unit)\n if not ok then __wrap_lua__error(message) end\nend"
},{
"key":"5",
"filter":{
"slotKey":-2,
"signature":"actionStart(action)",
"args":[{
"variable":"*"
}]
},
"code":"if not __wrap_lua__stopped and script.onActionStart then\n local ok, message = xpcall(script.onActionStart,__wrap_lua__traceback,action,system)\n if not ok then __wrap_lua__error(message) end\nend"
},{
"key":"6",
"filter":{
"slotKey":-2,
"signature":"actionStop(action)",
"args":[{
"variable":"*"
}]
},
"code":"if not __wrap_lua__stopped and script.onActionStop then\n local ok, message = xpcall(script.onActionStop,__wrap_lua__traceback,action,system)\n if not ok then __wrap_lua__error(message) end\nend"
},{
"key":"7",
"filter":{
"slotKey":-2,
"signature":"actionLoop(action)",
"args":[{
"variable":"*"
}]
},
"code":"if not __wrap_lua__stopped and script.onActionLoop then\n local ok, message = xpcall(script.onActionLoop,__wrap_lua__traceback,action,system)\n if not ok then __wrap_lua__error(message) end\nend"
},{
"key":"8",
"filter":{
"slotKey":-2,
"signature":"update()",
"args":[]
},
"code":"if not __wrap_lua__stopped and script.onUpdate then\n local ok, message = xpcall(script.onUpdate,__wrap_lua__traceback,system)\n if not ok then __wrap_lua__error(message) end\nend"
},{
"key":"9",
"filter":{
"slotKey":-2,
"signature":"flush()",
"args":[]
},
"code":"if not __wrap_lua__stopped and script.onFlush then\n local ok, message = xpcall(script.onFlush,__wrap_lua__traceback,system)\n if not ok then __wrap_lua__error(message) end\nend"
}],
"methods":[],
"events":[]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment