-
Notifications
You must be signed in to change notification settings - Fork 13
Home
Welcome to the MetaScript wiki! For now, the wiki contains a few non-trivial insights on writing meta.
//? if (NODE)
buffer.writeInt8(offset, value);
//? else
view.setInt8(value, offset);
This will actually work without using curly braces because each source line is wrapped by a dedicated write(...)
call, resulting in the following meta program:
if (NODE)
write('buffer.writeInt8(offset, value);\n');
else
write('view.setInt8(value, offset);\n');
The MetaScript compiler makes sure to retain any white spaces and line breaks, except if a meta line or block is the only contents of a line, in which case the line break and white spaces will be skipped. In the example from above:
if (true) {
//? if (NODE)
buffer.writeInt8(offset, value);
//? else
view.setInt8(value, offset);
}
the result will not contain any white spaces or new lines where the meta statements are, like, for NODE=true
, so:
if (true) {
buffer.writeInt8(offset, value);
}
But if you explicitly require indentation, you may use the indent(str:string, indent:string|number):string
utility:
//? write(indent('hi!', 4))
which will result in:
hi!
When inspecting the generated meta program, you will notice that the variable __
is used quite frequently. It stores the indentation level of the last meta block processed. For example ...
//? if (NODE)
//? include("node-stuff.js");
//? else
//? include("browser-stuff.js");
... will indent the contents of the included filesby four spaces (just like before //?
), while ...
/*? if (NODE)
include("node-stuff.js");
else
include("browser-stuff.js"); */
will not, just like before /*?
. When creating custom utility functions, it's of course safe to use this variable on your own.