summaryrefslogtreecommitdiffstats
path: root/src/Bindings/LuaState.h
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2016-08-23 13:20:43 +0200
committerMattes D <github@xoft.cz>2016-08-23 13:20:43 +0200
commit5ca371bb9a65cc322eb8327d81709985daefe173 (patch)
tree41f9d786c52985118f444d86721649e1186e6b2d /src/Bindings/LuaState.h
parentcUrlClient: Refactored callbacks to use UniquePtr. (diff)
downloadcuberite-5ca371bb9a65cc322eb8327d81709985daefe173.tar
cuberite-5ca371bb9a65cc322eb8327d81709985daefe173.tar.gz
cuberite-5ca371bb9a65cc322eb8327d81709985daefe173.tar.bz2
cuberite-5ca371bb9a65cc322eb8327d81709985daefe173.tar.lz
cuberite-5ca371bb9a65cc322eb8327d81709985daefe173.tar.xz
cuberite-5ca371bb9a65cc322eb8327d81709985daefe173.tar.zst
cuberite-5ca371bb9a65cc322eb8327d81709985daefe173.zip
Diffstat (limited to '')
-rw-r--r--src/Bindings/LuaState.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h
index cb68b9a98..32d346a19 100644
--- a/src/Bindings/LuaState.h
+++ b/src/Bindings/LuaState.h
@@ -301,6 +301,26 @@ public:
return cLuaState(m_Ref.GetLuaState()).CallTableFn(m_Ref, a_FnName, std::forward<Args>(args)...);
}
+ /** Calls the Lua function stored under the specified name in the referenced table, if still available.
+ A "self" parameter is injected in front of all the given parameters and is set to the callback table.
+ Returns true if callback has been called.
+ Returns false if the Lua state isn't valid anymore, or the function doesn't exist. */
+ template <typename... Args>
+ bool CallTableFnWithSelf(const char * a_FnName, Args &&... args)
+ {
+ auto cs = m_CS;
+ if (cs == nullptr)
+ {
+ return false;
+ }
+ cCSLock Lock(*cs);
+ if (!m_Ref.IsValid())
+ {
+ return false;
+ }
+ return cLuaState(m_Ref.GetLuaState()).CallTableFn(m_Ref, a_FnName, m_Ref, std::forward<Args>(args)...);
+ }
+
/** Set the contained reference to the table in the specified Lua state's stack position.
If another table has been previously contained, it is unreferenced first.
Returns true on success, false on failure (not a table at the specified stack pos). */
@@ -741,6 +761,10 @@ public:
Returns nullptr if the canon Lua state cannot be queried. */
cLuaState * QueryCanonLuaState(void);
+ /** Outputs to log a warning about API call being unable to read its parameters from the stack,
+ logs the stack trace and stack values. */
+ void LogApiCallParamFailure(const char * a_FnName, const char * a_ParamNames);
+
protected:
cCriticalSection m_CS;