2021-09-03 05:11:04 +00:00
|
|
|
#include "ScriptTypes.h"
|
|
|
|
#include "ScriptSystem.h"
|
|
|
|
#include "ScriptWorker.h"
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2021-09-03 05:11:04 +00:00
|
|
|
#pragma once
|
2017-08-18 05:08:22 +00:00
|
|
|
|
|
|
|
class CScriptInstance
|
|
|
|
{
|
2021-09-03 05:11:04 +00:00
|
|
|
private:
|
|
|
|
JSInstanceName m_InstanceName;
|
|
|
|
CScriptSystem* m_System;
|
|
|
|
duk_context* m_Ctx;
|
|
|
|
size_t m_RefCount;
|
|
|
|
uint64_t m_ExecTimeout;
|
|
|
|
uint64_t m_ExecStartTime;
|
|
|
|
std::ifstream m_SourceFile;
|
|
|
|
char* m_SourceCode;
|
|
|
|
JSAppCallbackID m_CurExecCallbackId;
|
|
|
|
std::vector<CScriptWorker*> m_Workers;
|
|
|
|
bool m_bStopping;
|
2018-02-18 21:37:03 +00:00
|
|
|
|
2017-08-18 05:08:22 +00:00
|
|
|
public:
|
2021-09-03 05:11:04 +00:00
|
|
|
CScriptInstance(CScriptSystem* sys, const char* name);
|
2017-09-13 10:36:03 +00:00
|
|
|
~CScriptInstance();
|
2017-08-18 05:08:22 +00:00
|
|
|
|
2021-09-03 05:11:04 +00:00
|
|
|
JSInstanceName& Name();
|
|
|
|
CScriptSystem* System();
|
|
|
|
CDebuggerUI* Debugger();
|
|
|
|
JSAppCallbackID CallbackId();
|
2018-02-18 21:37:03 +00:00
|
|
|
|
2021-09-03 05:11:04 +00:00
|
|
|
bool Run(const char* path);
|
|
|
|
void SetExecTimeout(uint64_t timeout);
|
|
|
|
bool IsTimedOut();
|
2017-09-13 10:36:03 +00:00
|
|
|
|
2021-09-03 05:11:04 +00:00
|
|
|
size_t GetRefCount();
|
|
|
|
void IncRefCount();
|
|
|
|
void DecRefCount();
|
|
|
|
void SetStopping(bool bStopping);
|
|
|
|
bool IsStopping();
|
2017-09-13 10:36:03 +00:00
|
|
|
|
2021-09-03 05:11:04 +00:00
|
|
|
bool RegisterWorker(CScriptWorker* worker);
|
|
|
|
void UnregisterWorker(CScriptWorker* worker);
|
|
|
|
void StopRegisteredWorkers();
|
2017-09-13 10:36:03 +00:00
|
|
|
|
2021-09-03 05:11:04 +00:00
|
|
|
void RawInvokeAppCallback(JSAppCallback& cb, void *_hookEnv);
|
2017-09-13 10:36:03 +00:00
|
|
|
|
2021-09-03 05:11:04 +00:00
|
|
|
void RawConsoleInput(const char* code);
|
2017-09-13 10:36:03 +00:00
|
|
|
|
2021-09-03 05:11:04 +00:00
|
|
|
void RawCall(void* dukFuncHeapPtr, JSDukArgSetupFunc argSetupFunc, void* param = nullptr);
|
2017-09-13 10:36:03 +00:00
|
|
|
|
2021-09-03 05:11:04 +00:00
|
|
|
void RawCMethodCall(void* dukThisHeapPtr, duk_c_function func,
|
|
|
|
JSDukArgSetupFunc argSetupFunc = nullptr,
|
|
|
|
void* argSetupParam = nullptr);
|
2017-09-13 10:36:03 +00:00
|
|
|
|
2021-09-03 05:11:04 +00:00
|
|
|
void PostCMethodCall(void* dukThisHeapPtr, duk_c_function func,
|
|
|
|
JSDukArgSetupFunc argSetupFunc = nullptr,
|
|
|
|
void* argSetupParam = nullptr, size_t argSetupParamSize = 0);
|
2017-09-13 10:36:03 +00:00
|
|
|
|
2021-09-03 05:11:04 +00:00
|
|
|
private:
|
|
|
|
static uint64_t Timestamp();
|
|
|
|
void Cleanup();
|
2021-03-18 03:43:39 +00:00
|
|
|
};
|