2,732
edits
Red Leader (talk | contribs) (→write_properties(): More doc) |
Red Leader (talk | contribs) (→write_properties(): Finish doc) |
||
Line 366: | Line 366: | ||
{{Nasal doc | {{Nasal doc | ||
|syntax = io.write_properties(path, prop); | |syntax = io.write_properties(path, prop); | ||
|text = Writes nodes from the [[Property Tree]] to an XML file in FlightGear's [[PropertyList XML files|PropertyList]] format. Returns the filename on success or <code>'''nil'''</code> on error. | |text = Writes nodes from the [[Property Tree]] to an XML file in FlightGear's [[PropertyList XML files|PropertyList]] format. If the file does not exist, it will be created. If it does, all contents will be overwritten. Returns the filename on success or <code>'''nil'''</code> on error. | ||
|param1 = path | |param1 = path | ||
|param1text = Path of the file to write to. | |param1text = Path of the file to write to. If it does not have a <tt>.xml</tt> extension, <tt>.xml</tt> will be added to it. | ||
| | |param2 = prop | ||
| | |param2text = Either a property path or a <code>props.Node</code> object. Note that, when the latter is used, results will be more accurate if it refers to a node in the Property Tree, otherwise the node will have to be copied, which may change the node type. | ||
|example1 = var | |example1 = var path = getprop("/sim/fg-home") ~ '/Export/demo.xml'; | ||
var prop = "/position"; | |||
io.write_properties( | print(io.write_properties(path, prop)); | ||
|example2 = var path = getprop("/sim/fg-home") ~ '/Export/demo.xml'; | |||
var prop = props.globals.getNode("position"); | |||
print(io.write_properties(path, prop)); | |||
|example3 = var path = getprop("/sim/fg-home") ~ '/Export/demo.xml'; | |||
var tree = { | |||
"a": 12.34, | |||
"b": "Hello, World!", | |||
"c": { | |||
"d": [1, 2, 3] | |||
} | |||
}; | |||
var prop = props.Node.new(tree); | |||
print(io.write_properties(path, prop)); | |||
}} | }} | ||