Thread:Extension talk:Scribunto/Check whether title exists, otherwise load data

Thank you for all your help. This test full of flags is convincing the Catalan Wikipedia and I got permission to start introducing slowly the new Lua based template in pages full of flags.

I'm stuck trying to interpret the Lua reference manual and understand whether this is possible (no real syntax attempted):

given the parameter "Andorra" if Module:Flags/Data is not loaded then do   if "File:Flag_of_Andorra.svg" exists then imageName = "File:Flag of Andorra.svg" else mw.loadData("Module:Flags/Data") end if... (the search continues in Flags/Data)

The idea being that in pages with one or few obvious flags the template can provide the flag without loading the big table. However, if an attempt fails then Flags/Data is loaded and from that point we forget about the more expensive function to check whether the file exists.

Reading the documentation is unclear to me whether using mw.loadData we can check whether a module is loaded or not, and how. I'm also missing an example explaining how to use the title object "exists" just to check whether a page exists, without attempting to create a new one.