6#ifndef MB_SCRIPTING_ENGINE_H
7#define MB_SCRIPTING_ENGINE_H
9#ifdef MB_SCRIPTING_ENABLED
11#include <dukglue/dukglue.h>
17typedef struct duk_hthread duk_context;
32 explicit MbScriptingEngine(MantisBase &app);
35 MbScriptingEngine(
const MbScriptingEngine &) =
delete;
36 MbScriptingEngine &operator=(
const MbScriptingEngine &) =
delete;
42 void loadStartScript();
45 void loadScript(
const std::string &relativePath);
47 void fireOnServerStart();
48 void fireOnServerShutdown();
49 void fireOnRecordCreated(
const std::string &entity,
const std::string &recordId);
50 void fireOnRecordUpdated(
const std::string &entity,
const std::string &recordId);
52 [[nodiscard]] duk_context *ctx()
const {
return m_ctx; }
53 [[nodiscard]]
bool isActive()
const {
return m_ctx !=
nullptr; }
56 [[nodiscard]]
static MbScriptingEngine *active();
60 auto withLock(Fn &&fn) ->
decltype(fn()) {
61 std::lock_guard lock(m_mutex);
65 bool pcallBool(
const DukValue &fn, MbRequest &req, MbResponse &res);
66 void pcallVoid(
const DukValue &fn, MbRequest &req, MbResponse &res);
69 void registerBindings()
const;
70 void evalFile(
const std::string &filePath);
71 void evalString(
const std::string &content,
const std::string &label);
72 [[nodiscard]]
bool isRuntimeDisabled()
const;
75 duk_context *m_ctx =
nullptr;
76 mutable std::mutex m_mutex;
77 static MbScriptingEngine *s_active;
MantisBase entry point.
Definition mantisbase.h:54
HTTP request wrapper bound to a MantisBase instance.
Definition http.h:66
HTTP response wrapper bound to a MantisBase instance.
Definition http.h:213
#define MANTISBASE_API
Definition export.h:31
Core type aliases, handler signatures, and the MbAppMixin DI mixin.