Lua - radishengine/drowsy GitHub Wiki

SquareScript translations

Local Variables

Lua:

local var1, var, var3 = 1, 2, 3

SquareScript:

['< >', 'var1', 'var2', 'var3'],
['set', ['var1'], 1],
['set', ['var2'], 2],
['set', ['var3'], 3],

Global Variables

Lua:

someGlobal = someOtherGlobal + 10

SquareScript:

['< >', 'someGlobal', 'someOtherGlobal'],
['<^>', 'someGlobal'],
['<^>', 'someOtherGlobal],
['set', ['someGlobal', ['+', ['someOtherGlobal', 10]]]],

Define Table

Lua:

tbl = {a=1, b=2, c=3}
arr = {200, 500, 800}
tbl[arr] = 1000

SquareScript (where tbl and arr were previously defined as either local or global variables):

['set', ['tbl'], ['{}']],
['set', ['.', ['tbl'] 'a'], 1],
['set', ['.', ['tbl'] 'b'], 2],
['set', ['.', ['tbl'] 'c'], 3],
['set', ['arr'], ['{}']],
['set', ['.', ['arr'] 1], 200],
['set', ['.', ['arr'] 2], 500],
['set', ['.', ['arr'] 3], 800],
['set', ['.', ['tbl'], ['arr']], 1000],

Function Call

Lua:

func(1, 2, 3)

SquareScript (where func is previously defined as either a local or global variable):

['c()', ['func'], 1, 2, 3]

Method Call

Lua:

obj:someMethod(1, 2, 3)

SquareScript (where obj is previously defined as either a local or global variable):

['m()', ['.', ['obj'], 'someMethod'], 1, 2, 3]