1
0
Fork 0

add function to reload Nasal module at runtime. Very convenient for

development. The file must be an XML file with Nasal between a
header/footer. It's a good idea to give it a *.nas extension, so
that editors choose the Nasal syntax coloring.

  <PropertyList><script><![CDATA[

  ... here goes the Nasal code ...

  ]]></script></PropertyList>
This commit is contained in:
mfranz 2007-03-29 15:00:04 +00:00
parent d10d5980ca
commit abaa43a1a5

View file

@ -15,6 +15,8 @@
#
# debug.string(<variable>) ... returns contents of variable as string
#
# debug.load_xml_nasal(<file>) ... load and run XML embedded Nasal
#
@ -132,3 +134,42 @@ if (getprop("/sim/logging/priority") != "alert") {
}
##
# Loads embedded Nasal from an XML file into a Nasal namespace.
# The namespace is by default the file's basename. Optionally,
# a module can be defined in a <module> entry. The file name
# doesn't have to carry an *.xml extension. It may even be
# desirable to use *.nas, so that editors pick up Nasal syntax
# coloring.
#
# Usage: debug.load_xml_nasal(<filename>);
#
# Example:
#
# debug.load_xml_nasal("Aircraft/mine/test.nas");
#
# contents of test.nas:
#
# <PropertyList>
# <module>test</module> <!-- optional -->
# <script><![CDATA[
#
# print("I'm being reloaded.");
#
# ]]></script>
# </PropertyList>
#
var load_xml_nasal = func(file) {
var n = props.globals.getNode("/tmp/nasal", 1);
n.getNode("filename", 1).setValue(file);
n.getNode("targetnode", 1).setValue(n.getPath());
if (n.getNode("module", 0) == nil) {
var basename = split(".", split("/", file)[-1])[0];
n.getNode("module", 1).setValue(basename);
}
fgcommand("loadxml", n);
fgcommand("nasal", n);
}