79 posts
Location
Germany
Posted 01 August 2013 - 05:40 AM
If i work with basic APIs like this one
superU:
function hello()
print("Hello World");
end
and i want to use it in another file i do this
os.loadAPI("superU")
superU.hello();
how do i use it when the name of the api isn't superU but "
superU.properties"?
Thanks for your help.
331 posts
Posted 01 August 2013 - 06:08 AM
I would say your wanting to access it when its saved as something else I would probably store it to a directory called api ( put all api's in there) and then do a code like
apis = fs.list("/api") for I = 1, #apis do os.loadApi(apis[I]) end
16 posts
Posted 01 August 2013 - 03:11 PM
I don't have time to look at the os.loadAPI function right now but I think this is the only way to do it.
Expose your properties object or "sub-api" as a part of the superU api
file: superU
properties = {
fun="yes",
goodbye = function ()
print("Goodbye")
end
}
function hello()
print("Hello World")
end
This would enable you to access the properties table just like you accessed the hello function. They're both contained in the superU api.
os.loadAPI("superU")
superU.hello()
print("This is "..superU.properties.fun.."!")
superU.properties.goodbye()
I don't think you'd be able to simply save your api file as "superU.properties" and load it as an api. The period [.] is a special character when it comes to referencing variables.
8543 posts
Posted 01 August 2013 - 03:52 PM
If the filename is SuperU.properties, you would need to use _G["SuperU.properties"].whatever() to access the whatever() function it contained.
Don't use periods in API names.
79 posts
Location
Germany
Posted 07 August 2013 - 04:24 AM
Thanks for your help:
If the filename is SuperU.properties, you would need to use _G["SuperU.properties"].whatever() to access the whatever() function it contained.
Don't use periods in API names.
997 posts
Location
Wellington, New Zealand
Posted 07 August 2013 - 04:51 AM
You could rename it, quite easily:
_G.superU = _G["superU.properties"]
_G["superU.properties"] = nil
I hope it's clear how this works.