Lua interface
Lua features are accessible via Lua structure.
Exporting a value
To produce a Lua module, use --lib compiler option and define a variable or structure named export.
For example,
val export = <some value>;
will compile to
return <some value>
and
structure export = struct
val foo = "string"
val bar = 42
val fun' = "fun" (* SML keywords can be escaped by suffixing with a prime *)
end
will compile to:
return {
foo = "string",
bar = 42,
fun = "fun",
}
Internal representation
Warning: The internal representation of data types may change in the future. Do not rely on it!
unit(empty record)nil.boolLua’s boolean;
trueorfalse.intLua 5.3 or later: Lua’s native integer (typically 64-bit). LuaJIT: 54-bit signed integer, using Lua’s native number. Overflows are always checked.
wordLua 5.3 or later: Lua’s native integer (typically 64-bit), using negative values for large values. LuaJIT: 32-bit unsigned integer, using Lua’s native number.
realLua’s native number, typically 64-bit.
char8-bit unsigned integer.
stringLua’s native string.
Int54.intLua 5.3 or later: Lua’s native integer. LuaJIT: Lua’s native number.
Int64.intLua 5.3 or later: Lua’s native integer. LuaJIT: Boxed 64-bit signed integer:
int64_t.Word64.wordLua 5.3 or later: Lua’s native integer. LuaJIT: Boxed 64-bit unsigned integer:
uint64_t.'a listnilforniland{ [1] = <head>, [2] = <tail> }for<head> :: <tail>.'a vector{ n = <length>, [1] = <0th element>, [2] = <1st element>, ... }; compatible withtable.pack.'a arraySame as
'a vector, but mutable.'a ref{ [1] = <the payload> }Lua.valueAny Lua value, including
nil.- Non-empty record
{ [1] = <#1 of the record>, foo = <#foo of the record> }