Native work Lua invokes in C++. More...
Classes | |
| class | AsyncCall |
| Asynchronous native call from Lua. More... | |
| class | BasicAsyncCall< R > |
| Asynchronous native call with result type R. More... | |
| class | BasicAsyncCall< void > |
| Asynchronous native call with no result. More... | |
| class | Call |
| Synchronous native call from Lua. More... | |
| class | MethodCall |
| Reflected method invocation from Lua. More... | |
| class | PropertyGetCall |
| Reflected property read from Lua. More... | |
| class | PropertySetCall |
| Reflected property write from Lua. More... | |
| class | ConstructorCall |
| Reflected constructor invocation from Lua. More... | |
Typedefs | |
| template<typename... As> | |
| using | AsyncFunction = Pt::Reflex::BasicFunction<AsyncCall*, As...> |
| Reflex function that returns an asynchronous Lua call. | |
Lua reaches C++ through the Reflex catalog the context bound. A method, property, or constructor becomes a Call. The script yields, reports NativeCall, runs that call, and pushes the result back to Lua. The script owns the Call. Application code does not construct MethodCall, PropertyGetCall, PropertySetCall, or ConstructorCall.
A function or method whose return type is AsyncCall* is an asynchronous native call. Lua invokes it, the function returns a heap AsyncCall, and the script takes ownership. The script must be attached to an EventLoop. It binds the call, starts it with the loop, and resumes when finished() is emitted. Blocking advance() throws if such a call is pending.
Implement async work by subclassing BasicAsyncCall. For a result type R, override onBeginCall() to start work on the loop, onResult() to produce R, and onCancel() to abort. For void, there is no onResult(). Call setReady() when the work is done, or setError() if it failed. AsyncFunction is a Reflex function helper whose return type is already AsyncCall*.
The example is a timer wait registered as a Lua global. The script must use beginAdvance() on an event loop.
| using AsyncFunction = Pt::Reflex::BasicFunction<AsyncCall*, As...> |
Alias for a Pt::Reflex::BasicFunction whose result type is AsyncCall*. Register an instance, or a free function with that return type, so Lua can invoke asynchronous native work.