Export Functions
Guide to export functions from your plugin to be used by other language modules within Plugify.
In the Plugify ecosystem, Lua plugins can export functions to make them accessible to other plugins. This guide explains how to define and export functions in Lua and provides examples to help you integrate your plugins seamlessly.
Basic Type Mapping
The following table lists how types are exposed to the Lua API:
C++ Type | Lua Type | Plugify Alias | Ref Support ? |
---|---|---|---|
void | nil | void | ❌ |
bool | boolean | bool | ✅ |
char | string | char8 | ✅ |
char16_t | string | char16 | ✅ |
int8_t | integer | int8 | ✅ |
int16_t | integer | int16 | ✅ |
int32_t | integer | int32 | ✅ |
int64_t | integer | int64 | ✅ |
uint8_t | integer | uint8 | ✅ |
uint16_t | integer | uint16 | ✅ |
uint32_t | integer | uint32 | ✅ |
uint64_t | integer | uint64 | ✅ |
uintptr_t | integer | ptr64 | ✅ |
uintptr_t | integer | ptr32 | ✅ |
float | number | float | ✅ |
double | number | double | ✅ |
void* | function | function | ❌ |
plg::string | string | string | ✅ |
plg::any | any | any | ✅ |
plg::vector<bool> | table | bool[] | ✅ |
plg::vector<char> | table | char8[] | ✅ |
plg::vector<char16_t> | table | char16[] | ✅ |
plg::vector<int8_t> | table | int8[] | ✅ |
plg::vector<int16_t> | table | int16[] | ✅ |
plg::vector<int32_t> | table | int32[] | ✅ |
plg::vector<int64_t> | table | int64[] | ✅ |
plg::vector<uint8_t> | table | uint8[] | ✅ |
plg::vector<uint16_t> | table | uint16[] | ✅ |
plg::vector<uint32_t> | table | uint32[] | ✅ |
plg::vector<uint64_t> | table | uint64[] | ✅ |
plg::vector<uintptr_t> | table | ptr64[] | ✅ |
plg::vector<uintptr_t> | table | ptr32[] | ✅ |
plg::vector<float> | table | float[] | ✅ |
plg::vector<double> | table | double[] | ✅ |
plg::vector<plg::string> | table | string[] | ✅ |
plg::vector<plg::any> | table | any[] | ✅ |
plg::vector<plg::vec2> | table | vec2[] | ✅ |
plg::vector<plg::vec3> | table | vec3[] | ✅ |
plg::vector<plg::vec4> | table | vec4[] | ✅ |
plg::vector<plg::mat4x4> | table | mat4x4[] | ✅ |
plg::vec2 | Vector2 | vec2 | ✅ |
plg::vec3 | Vector3 | vec3 | ✅ |
plg::vec4 | Vector4 | vec4 | ✅ |
plg::mat4x4 | Matrix4x4 | mat4x4 | ✅ |
Exporting Functions in Lua
Lua functions can be exported by defining them in your plugin and referencing them in the .pplugin
manifest. Plugify’s Lua Language Module will handle the necessary type conversions.
Basic Example
Here’s a simple example of exporting a function in a Lua plugin:
Function Definition
Plugin Manifest
To export the function, describe it in the plugin manifest under the exportedMethods
section:
Advanced Example: Exporting Complex Functions
Here’s an example of exporting a function with complex parameter and return types:
Function Definition
Plugin Manifest
Handling Callbacks
Plugify allows you to export functions that accept callbacks as parameters. Here’s an example:
Function Definition
Plugin Manifest
Best Practices
- Define Functions Clearly: Ensure your functions are well-documented and easy to understand.
- Follow Type Conventions: Adhere to Plugify's type conventions for parameters and return values.
- Test Thoroughly: Test your exported functions to ensure they work as expected when called by other plugins.
- Update the Manifest: Always describe exported functions in the plugin manifest under the
exportedMethods
section.
Conclusion
Exporting functions in Lua plugins is clean and flexible. Just define your functions, register them in your manifest, and they become accessible to other modules. For more advanced scenarios, including passing callbacks, refer to the examples in this guide.