API ReferenceGE Extensionsutil
Test Extension Proxies
Demonstration/test extension showing how to use `newExtensionProxy` to fan out extension hooks to multiple object instances.
Demonstration/test extension showing how to use newExtensionProxy to fan out extension hooks to multiple object instances.
Overview
util_testExtensionProxies creates an ExtensionProxy that dispatches extension events (like onUpdate) to a list of OOP instances. This is a test/example extension - not used in production.
Extension path: lua/ge/extensions/util/testExtensionProxies.lua
Exports (M)
| Function | Signature | Description |
|---|---|---|
onExtensionLoaded | () | Creates 11 test instances and registers them with an ExtensionProxy. |
onExtensionUnloaded | () | Destroys the ExtensionProxy. |
Internals
ExtensionProxyTester Class
A minimal class with an onUpdate method that prints its id and dtReal.
function ExtensionProxyTester:onUpdate(dtReal, dtSim, dtRaw)
print('ExtensionProxyTester:onUpdate called: ' .. tostring(self.id) .. ', ' .. tostring(dtReal))
endExtensionProxy Pattern
- Create instances with event-sink methods (e.g.,
onUpdate). - Call
newExtensionProxy(M)- binds the proxy to this extension module. - Call
extProxy:submitEventSinks(instances)- registers instances as event receivers. - When the extension receives
onUpdate, the proxy fans it out to all instances. - On unload, call
extProxy:destroy()to clean up.
How It Works
onExtensionLoadedcreates 11ExtensionProxyTesterobjects (ids 0–10).- An
ExtensionProxyis created and given the instances. - Every frame, each instance's
onUpdateis called with the frame's dt values. onExtensionUnloadeddestroys the proxy.
Lua Examples
-- Load the test extension
extensions.load("util/testExtensionProxies")
-- Console will print 11 onUpdate messages per frame
-- The pattern for your own extension:
local proxy = newExtensionProxy(M)
proxy:submitEventSinks(myInstances)
-- Later:
proxy:destroy()Additional Exports
M.onExtensionLoaded- (undocumented)M.onExtensionUnloaded- (undocumented)