Skip to content
This repository has been archived by the owner on May 27, 2021. It is now read-only.

Arguments

MJ edited this page Oct 8, 2016 · 2 revisions

Arguments

You can pass any arguments from Java to LmlData using #addArgument(String, Object). Arguments can be used in LML templates, effectively replacing the LML content with the data that you set in Java. (Note: arguments also supports arrays and iterables, which will be converted to LML arrays; more on LML arrays later.)

Arguments are accessible {likeThat}. For example, by registering these attributes:

lmlParser.getData().addArgument("defPad", 3);
lmlParser.getData().addArgument("title", "MyGame:v1.3");
<!-- This: -->
<window title={title}>
  <label pad={defPad}>(...)</label>
</window>

<!-- ...will be converted to: -->
<window title=MyGame:v1.3>
  <label pad=3>(...)</label>
</window>

Arguments can be changed and assigned during parsing - thanks to macros. More on macros later. Be aware that arguments are often equivalent of variables in LML: they can be assign and read, and often become additional parameters during macro processing. For example, you can access current iteration index then using loop macro.

Quick argument registration during parser building:

Lml.parser().argument("argumentId", argumentValue)
    // TODO Other parser settings.
    .build();