LunaLua global API functions

From PGE Wiki
Jump to navigation Jump to search

This is the new softcoded API system for custom written libraries. It provides functions to easily load libraries and provides ways for libraries to hook into events.

Global API Functions
Function Return values Description
loadAPI(string packagename) (Deprecated: Use API.load) table api, boolean newLoaded Loads the library packagename.lua. Do load it outside every other function! (Recommended at the top of your scriptfile). newLoaded is false if the library is already loaded.
loadSharedAPI(string packagename) (Deprecated: Use API.load) table api, boolean newLoaded Loads the library packagename.lua and shares it with lunadll.lua and lunaworld.lua. Do load it outside every other function! (Recommended at the top of your scriptfile). newLoaded is false if the library is already loaded.
v0.7.3 and up:
API.load(string packagename, boolean loadShared)
table api, boolean newLoaded Loads the library packagename.lua and shares it with lunadll.lua and lunaworld.lua unless loadShared is set to false (set to true by default). Do load it outside every other function! (Recommended at the top of your scriptfile). newLoaded is false if the library is already loaded.
Before v0.4:
registerEvent(string libraryname, string event, [string eventHandler], [boolean beforeMainCall])
nil Register events in the event loop. libraryname is the package name of the library (name of the library table). event is the name of the event to be hooked in. If your event-function has a own name then you can set eventHandler (This is optional). If beforeMainCall set to false then this event will be called after the main function call. If set to true or this parameter is not passed then the function is called before the main call.
v0.4 and up:
registerEvent(table thisTable, string event, [string eventHandler], [boolean beforeMainCall])
nil Register events in the event loop. thisTable is the package table of the library. event is the name of the event to be hooked in. If your event-function has a own name then you can set eventHandler (This is optional). If beforeMainCall set to false then this event will be called after the main function call. If set to true or this parameter is not passed then the function is called before the main call.
v0.4 and up:
unregisterEvent(table thisTable, string event, string eventHandler)
nil Unregisters a event.
v0.7.2.3 and up:
registerCustomEvent(table thisTable, string event)
nil Creates a custom event (such as onTick) for the library given as the first argument. Once the function is registered, it can be called from within the library like any other function, and can be defined by the user like any other event.
isAPILoaded(table libraryObject) boolean Checks if a library is loaded by the lunalua API, using the return value of the API.load call to check.
isAPILoaded(string libraryName) boolean Checks if a library is loaded by the lunalua API, using the name of the library to check.

API Events

Global API Functions
Function Return values Description
onInitAPI() nil This function is called when it's getting loaded by the API.load-function. It is recommended to use this function to hook in all required events.