In lua I’m trying to read an xml configuration file located in UserDocumentsDir.
I’m a bit lost as an XMLFile is a resource and mine is not located in the cache, so I can’t use GetResource() function.
[SOLVED] Reading a xml file in lua


You can’t at the moment Lua doesn’t have the XMLFile::Load(File) functionality exposed to be able to load from outside the ResourceCache.

If you check Resource.pkg, there should be the following registered, which takes filename as a string:
tolua_outside bool ResourceLoad @ Load(const String fileName);
Would that work?

I’ve tried (myFile is the xml file with its path):
local config = XMLFile()
config:Load(File(myFile, FILE_READ))
or
config:Load(myFile)
Maybe I’m doing something wrong (I get inspiration from Editor).

Mike you can’t do that at the moment, the XMLFile Load method isn’t exposed to Lua.
Lasse’s answer is probably the one you’re after.

Isn’t there a bug in ResourceLoad() function that calls Save instead of Load ?

Indeed that was bugged. It should now be fixed. An example:
local xml = XMLFile()
xml:Load(fileSystem:GetProgramDir() .. "Data/Materials/Stone.xml")
print(xml:GetRoot().name)

Cool, now everything is fine
What do you think of integrating this to sample #14 SoundEffects to transform it to a jukebox (along with a more sexy interface) ?

Sure, it’s good to show some more non-traditional use (I mean, not an engine resource per se) of XMLFile.

I’ll give it a try thursday, being out until then.
It’s really convenient to have a generic Load function for any kind of resource outside of the cache.
Many thanks to Aster for his great job.