LunaLua global API functions

From PGE Wiki
Jump to: navigation, search

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

Global API Functions
Function Return values Description
loadAPI(string packagename) (Deprecated: Use the below) table api, boolean newLoaded Loads the api packagename.lua. Do load it outside every other function! (Recommended at the top of your scriptfile). newLoaded is false if the api is already loaded.
loadSharedAPI(string packagename) (Deprecated: Use the below) table api, boolean newLoaded Loads the api 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 api is already loaded.
v0.7.3 and up:
API.load(string packagename, boolean loadShared)
table api, boolean newLoaded Loads the api 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 api is already loaded.
Before v0.4:
registerEvent(string apiName, string event, [string eventHandler], [boolean beforeMainCall])
nil Register events in the event loop. apiName is the package name of the api. 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 api. 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 onLoop) for the API given as the first argument. Once the function is registered, it can be called from within the API like any other function, and can be defined by the user like any other event.
isAPILoaded(table apiObject) boolean Checks if an API is loaded by a API object.
isAPILoaded(string apiName) boolean Checks if an API is loaded by a API name.

API Events

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