Files
fs2open.github.com/code/scripting/api/objs/tracing_category.cpp
T
asarium 04174e00f8 Ensure Lua functions are executed in correct state
This will ensure that Lua functions will always be executed in the
correct Lua state. Since we now have multiple threads (which are
different lua_State objects) it is possible that the current code could
execute a Lua function in the main state instead of the thread that is
currently executing. This can lead to weird behavior and probably also
to issues inside Lua.
2020-06-06 14:00:23 +02:00

35 lines
759 B
C++

#include "tracing_category.h"
#include "tracing/tracing.h"
namespace scripting {
namespace api {
ADE_OBJ(l_TracingCategory, tracing::Category, "tracing_category", "A category for tracing engine performance");
ADE_FUNC(trace,
l_TracingCategory,
"function body()",
"Traces the run time of the specified function that will be invoked in this call.",
nullptr,
nullptr)
{
tracing::Category* category = nullptr;
luacpp::LuaFunction func;
if (!ade_get_args(L, "ou", l_TracingCategory.GetPtr(&category), &func)) {
return ADE_RETURN_NIL;
}
if (!func.isValid()) {
LuaError(L, "Invalid function reference passed!");
return ADE_RETURN_NIL;
}
TRACE_SCOPE(*category);
func(L);
return ADE_RETURN_NIL;
}
} // namespace api
} // namespace scripting