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:
parent
d10d5980ca
commit
abaa43a1a5
1 changed files with 41 additions and 0 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue