-
Notifications
You must be signed in to change notification settings - Fork 14
3. Types
Numbers work the same way as they do in Lua:
local a = 10
local c = 15.3
local c = 30e10
local b = 0xFF
local d = 0b1011
Note that not all versions and modifications Lua may support all of these ways to make numbers.
Booleans use different operators:
-
and
->&&
-
or
->||
-
not
->!
if (condition1 && condition2) || !condition3 {
//...
}
Strings can now be multilined, but when compiling Clue will ignore every newline and tab:
local longstr = "
this is \n
a multilined-
string!
"
This code will be compiled to:
local longstr = "this is \na multilined-string!";
NOTE: Clue will only ignore tabs, it won't ignore them if you indentate with tabs! It wont ignore spaces.
Clue also offers raw strings which preserve newlines and tabs more like Lua's multiline strings. Raw strings are wrapped in `
:
local rawstring = `this
is a
raw string`
This code will be compiled to:
local rawstring = [[this
is a
raw string]]
Tables work the same way they do in Lua, but with a few additions:
If you're not sure if you're indexing a table or not you can use ?.
, ?[
or ?::
to check beforehand:
x = a.b?.c;
y = a?.b.c;
z = a?.b?.c;
This code will be compiled to:
x = (a.b and a.b.c);
y = (a and a.b.c);
z = (a and a.b and a.b.c);
Note that it only checks if the variable exists, it does not check if it's a table or something that can be indexed.
Also note that calling functions while using conditional indexing may sometimes lead the output to call the function/method more than once.
Metatables get a little easier to do with the new meta
keyword:
local mytable = {
x = 3,
meta index = {b = 5}
};
This table would have a metatable with the __index
metamethod that points to the table {b = 5}
.
All metamethods names are the same as Lua's but without the __
, except for a few operator related metamethods that can use the operator itself:
local othertable = {
meta + = fn() {/* ... */}
};
An external table can also be used as a metatable with the meta with
keyword:
local mt = {
__add = fn() {
//...
}
}
local t = {meta with mt}
This would compile to:
local mt = {
__add = function()
end
}
local t = setmetatable({},mt)