Common Utilities

VS Code Debugger

We devloped a VS Code debugger extension to help with debugging and inspecting lua code at runtime. This should always be an easier option than to add a dump or print and then needing to reload lua.

The extension can be found here: https://marketplace.visualstudio.com/items?itemName=beamng.luadbg

How to setup and use in a short and easy video:

Inspection Utilities

dumps(args)
Parameters:args – arguments to be converted to a string
Type args:variadic args
Returns:a string

Converts Lua variables into a string. Useful for debugging.

Example
1
2
3
4
> print(dumps({1, 2, 3}))
{ 1, 2, 3 }
> print(dumps(1, 2, 'abc', {'test', 3}))
1, 2, "abc", { "test", 3 }
dump(args)

Same as dumps(), just dumps it to the output.

> dump({1, 2, 3})
{ 1, 2, 3 }
> dumps(1, 2, 'abc', {'test', 3})
1, 2, "abc", { "test", 3 }
dumpToFile(filename, args)
Parameters:filename – which file to write to
Type filename:string

Same as dumps(), just dumps it to the output.

graphs(v, len)

TODO

Utilities

bytes_to_string(bytes)
Parameters:bytes – number of bytes
Type bytes:integer
Returns:string

Tiny utility function to format bytes. Scales from Kilobytes to Megabytes

Example:

> print(bytes_to_string(137))
0.13 KiB
> print(bytes_to_string(1337))
1.31 KiB
> print(bytes_to_string(13333337))
12.72 MiB
isint(number)
Parameters:number – number
Type number:number
Returns:bool

returns wheter the number provided is an integer number

> print(isint(123))
true
> print(isint(123.345))
false

Json

jsonWriteFile()
jsonDecode()

jsonReadFile

readDictJSONTable