Update to 1.10.0-beta1
This commit is contained in:
@@ -20,16 +20,21 @@ enum ScriptType {
|
||||
ST_GS, ///< The script is for Game scripts.
|
||||
};
|
||||
|
||||
struct ScriptAllocator;
|
||||
|
||||
class Squirrel {
|
||||
friend class ScriptAllocatorScope;
|
||||
|
||||
private:
|
||||
typedef void (SQPrintFunc)(bool error_msg, const SQChar *message);
|
||||
|
||||
HSQUIRRELVM vm; ///< The VirtualMachine instance for squirrel
|
||||
void *global_pointer; ///< Can be set by who ever initializes Squirrel
|
||||
SQPrintFunc *print_func; ///< Points to either NULL, or a custom print handler
|
||||
SQPrintFunc *print_func; ///< Points to either nullptr, or a custom print handler
|
||||
bool crashed; ///< True if the squirrel script made an error.
|
||||
int overdrawn_ops; ///< The amount of operations we have overdrawn.
|
||||
const char *APIName; ///< Name of the API used for this squirrel.
|
||||
std::unique_ptr<ScriptAllocator> allocator; ///< Allocator object used by this script.
|
||||
|
||||
/**
|
||||
* The internal RunError handler. It looks up the real error and calls RunError with it.
|
||||
@@ -93,7 +98,7 @@ public:
|
||||
* Adds a function to the stack. Depending on the current state this means
|
||||
* either a method or a global function.
|
||||
*/
|
||||
void AddMethod(const char *method_name, SQFUNCTION proc, uint nparam = 0, const char *params = NULL, void *userdata = NULL, int size = 0);
|
||||
void AddMethod(const char *method_name, SQFUNCTION proc, uint nparam = 0, const char *params = nullptr, void *userdata = nullptr, int size = 0);
|
||||
|
||||
/**
|
||||
* Adds a const to the stack. Depending on the current state this means
|
||||
@@ -155,7 +160,7 @@ public:
|
||||
* @return False if the script crashed or returned a wrong type.
|
||||
*/
|
||||
bool CallMethod(HSQOBJECT instance, const char *method_name, HSQOBJECT *ret, int suspend);
|
||||
bool CallMethod(HSQOBJECT instance, const char *method_name, int suspend) { return this->CallMethod(instance, method_name, NULL, suspend); }
|
||||
bool CallMethod(HSQOBJECT instance, const char *method_name, int suspend) { return this->CallMethod(instance, method_name, nullptr, suspend); }
|
||||
bool CallStringMethodStrdup(HSQOBJECT instance, const char *method_name, const char **res, int suspend);
|
||||
bool CallIntegerMethod(HSQOBJECT instance, const char *method_name, int *res, int suspend);
|
||||
bool CallBoolMethod(HSQOBJECT instance, const char *method_name, bool *res, int suspend);
|
||||
@@ -272,6 +277,31 @@ public:
|
||||
* Completely reset the engine; start from scratch.
|
||||
*/
|
||||
void Reset();
|
||||
|
||||
/**
|
||||
* Get number of bytes allocated by this VM.
|
||||
*/
|
||||
size_t GetAllocatedMemory() const noexcept;
|
||||
};
|
||||
|
||||
|
||||
extern ScriptAllocator *_squirrel_allocator;
|
||||
|
||||
class ScriptAllocatorScope {
|
||||
ScriptAllocator *old_allocator;
|
||||
|
||||
public:
|
||||
ScriptAllocatorScope(const Squirrel *engine)
|
||||
{
|
||||
this->old_allocator = _squirrel_allocator;
|
||||
/* This may get called with a nullptr engine, in case of a crashed script */
|
||||
_squirrel_allocator = engine != nullptr ? engine->allocator.get() : nullptr;
|
||||
}
|
||||
|
||||
~ScriptAllocatorScope()
|
||||
{
|
||||
_squirrel_allocator = this->old_allocator;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* SQUIRREL_HPP */
|
||||
|
||||
Reference in New Issue
Block a user