|
|
Line 144: |
Line 144: |
| }}</ref> | | }}</ref> |
|
| |
|
|
| |
| == main.nas ==
| |
|
| |
| <syntaxhighlight lang="javascript">
| |
|
| |
| var main = func(root) {
| |
|
| |
| print("my addon loaded !");
| |
|
| |
| }; # main()
| |
|
| |
| </syntaxhighlight>
| |
|
| |
|
| |
| In general, it is recommended to also register event handlers (/sim/signals) to deal with relevant events like pause/unpause, reset/reinit etc - for example, like this:
| |
| {{Main article|Using_listeners_and_signals_with_Nasal#Signals}}
| |
| <syntaxhighlight lang="javascript">
| |
|
| |
| setlistener("/sim/signals/reinit", func() {
| |
| print("addon: re-init !");
| |
| });
| |
|
| |
| setlistener("/sim/signals/exit", func() {
| |
| print("addon: exiting !");
| |
| });
| |
|
| |
| setlistener("/sim/signals/screenshot", func() {
| |
| print("addon: screentshot being taken");
| |
| });
| |
|
| |
|
| |
| </syntaxhighlight>
| |
|
| |
| It is also a good idea to overload settimer/setlistener respectively, to ensure that listeners/callbacks don't leak:
| |
| {{See also|Developing_and_debugging_Nasal_code#Managing_timers_and_listeners}}
| |
| <syntaxhighlight lang="javascript">
| |
|
| |
| </syntaxhighlight>
| |
|
| |
|
| == Implementation == | | == Implementation == |