![]() |
Cuberite
A lightweight, fast and extensible game server for Minecraft
|
Represents a stored callback to Lua that C++ code can call. More...
#include <LuaState.h>
Public Member Functions | |
template<typename... Args> | |
bool | Call (Args &&... args) |
Calls the Lua callback, if still available. More... | |
cCallback (void) | |
bool | RefStack (cLuaState &a_LuaState, int a_StackPos) |
Set the contained callback to the function in the specified Lua state's stack position. More... | |
![]() | |
void | Clear (void) |
Frees the contained reference, if any. More... | |
cTrackedRef (void) | |
Creates an unbound ref instance. More... | |
bool | IsSameLuaState (cLuaState &a_LuaState) |
Returns true if the reference resides in the specified Lua state. More... | |
bool | IsValid (void) |
Returns true if the contained reference is valid. More... | |
bool | RefStack (cLuaState &a_LuaState, int a_StackPos) |
Set the contained reference to the object at the specified Lua state's stack position. More... | |
~cTrackedRef () | |
Protected Member Functions | |
cCallback (cCallback &&)=delete | |
This class cannot be moved, because it is tracked in the LuaState by-ptr. More... | |
cCallback (const cCallback &)=delete | |
This class cannot be copied, because it is tracked in the LuaState by-ptr. More... | |
![]() | |
cTrackedRef (const cTrackedRef &)=delete | |
This class cannot be copied, because it is tracked in the LuaState by-ptr. More... | |
cTrackedRef (cTrackedRef &&)=delete | |
This class cannot be moved, because it is tracked in the LuaState by-ptr. More... | |
cRef & | GetRef () |
Returns the internal reference. More... | |
void | Invalidate (void) |
Invalidates the callback, without untracking it from the cLuaState. More... | |
Private Types | |
using | Super = cTrackedRef |
Additional Inherited Members | |
![]() | |
std::atomic< cCriticalSection * > | m_CS |
The mutex protecting m_Ref against multithreaded access. More... | |
cRef | m_Ref |
Reference to the Lua callback. More... | |
Represents a stored callback to Lua that C++ code can call.
Is thread-safe and unload-safe. When the Lua state is unloaded, the callback returns an error instead of calling into non-existent code. To receive the callback instance from the Lua side, use RefStack() or (better) cLuaState::GetStackValue() with a cCallbackPtr. Note that instances of this class are tracked in the canon LuaState instance, so that they can be invalidated when the LuaState is unloaded; due to multithreading issues they can only be tracked by-ptr, which has an unfortunate effect of disabling the copy and move constructors.
Definition at line 283 of file LuaState.h.
|
private |
Definition at line 286 of file LuaState.h.
|
inline |
Definition at line 290 of file LuaState.h.
|
protecteddelete |
This class cannot be copied, because it is tracked in the LuaState by-ptr.
Use cCallbackPtr for a copyable object.
|
protecteddelete |
This class cannot be moved, because it is tracked in the LuaState by-ptr.
Use cCallbackPtr for a copyable object.
|
inline |
Calls the Lua callback, if still available.
Returns true if callback has been called. Returns false if the Lua state isn't valid anymore.
Definition at line 296 of file LuaState.h.
bool cLuaState::cCallback::RefStack | ( | cLuaState & | a_LuaState, |
int | a_StackPos | ||
) |
Set the contained callback to the function in the specified Lua state's stack position.
If a callback has been previously contained, it is unreferenced first. Returns true on success, false on failure (not a function at the specified stack pos).
Definition at line 319 of file LuaState.cpp.