Skip to content

Instantly share code, notes, and snippets.

{
"slots":{
"0":{
"name":"screen",
"type":{
"methods":[],
"events":[]
},
"_elementType":"screen"
},
-- Define a global script object with event handlers
script = {}
function script.onStart ()
-- Display some text
screen.setCenteredText("script started")
-- Create some timers to show that the script is working
unit.setTimer("a", 2) -- timer id "a", ticks every 2 seconds
unit.setTimer("b", 3) -- timer id "b", ticks every 3 seconds
@d-lua-stuff
d-lua-stuff / wrap.lua
Last active January 11, 2021 11:28
Script packager/configurator for Dual Universe. See https://board.dualthegame.com/index.php?/topic/20161-lua-tool-script-packagerconfigurator-wraplua/ for more info. License: WTFPL
--------------------------------------------------------------------------------
-- wrap.lua bundle begins
-- version: 2020-09-04 6bd9a87
-- content sha256: 3f459084f0
--------------------------------------------------------------------------------
__lbs__version = "2020-09-04 6bd9a87"
do
do
local _ENV = _ENV
@d-lua-stuff
d-lua-stuff / json.lua
Created September 2, 2020 02:34
Functions for extracting values from a JSON string with pattern matching. This is faster than using dkjson when only a few fields are needed. License: WTFPL
-- Extracts values from a JSON string with pattern matching
-- This is faster than using dkjson when only a few fields are needed
-- Use this only with trusted data sources! Limitations:
-- * Character escapes are not supported
-- * Field nesting is ignored
local find, gsub = string.find, string.gsub
---@param json string
@d-lua-stuff
d-lua-stuff / dump_analyzer.py
Last active September 2, 2020 02:41
A script for extracting dump.lua output from *.xml log files. See https://board.dualthegame.com/index.php?/topic/20052-lua-all-global-variables/ for more info. License: WTFPL
# Extracts dump.lua output from *.xml log files
# Works with Python 2.7 and 3.6
# Dumped global variable members are internally represented by a unidirectional graph, which can contain cycles
import argparse
import errno
import os
import re
from collections import deque
@d-lua-stuff
d-lua-stuff / dump.lua
Last active September 1, 2022 16:03
Global variable dumping script for Dual Universe. See https://board.dualthegame.com/index.php?/topic/20052-lua-all-global-variables/ for more info. License: WTFPL
local max = math.max
local concat, insert = table.concat, table.insert
local byte, gsub, format, match, rep = string.byte, string.gsub, string.format, string.match, string.rep
local buffer = { "Lua globals dump: \r\n\r\n" }
local should_get_function_params = true
local should_dump_functions = false
local table_visited = {}
@d-lua-stuff
d-lua-stuff / main.c
Last active January 10, 2019 23:11
Lua console with debug.traceback() available as a global
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
// from https://www.lua.org/pil/24.2.3.html
static void stackDump(lua_State *L) {
int i;