From abaa43a1a5911f774729b09d5172f19dd27c417c Mon Sep 17 00:00:00 2001 From: mfranz Date: Thu, 29 Mar 2007 15:00:04 +0000 Subject: [PATCH] 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. --- Nasal/debug.nas | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) 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); +} + +