diff --git a/Nasal/debug.nas b/Nasal/debug.nas index 75a248045..7a8c5151b 100644 --- a/Nasal/debug.nas +++ b/Nasal/debug.nas @@ -15,6 +15,8 @@ # # debug.string() ... returns contents of variable as string # +# debug.load_xml_nasal() ... 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 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(); +# +# Example: +# +# debug.load_xml_nasal("Aircraft/mine/test.nas"); +# +# contents of test.nas: +# +# +# test +# +# +# +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); +} + +