[Scummvm-git-logs] scummvm master -> 7dfeb809f28f6fb14bc5eadd838125f331e04818
dreammaster
dreammaster at scummvm.org
Tue Jul 20 02:44:47 UTC 2021
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
7dfeb809f2 AGS: Refactored call_function to also use PluginMethod
Commit: 7dfeb809f28f6fb14bc5eadd838125f331e04818
https://github.com/scummvm/scummvm/commit/7dfeb809f28f6fb14bc5eadd838125f331e04818
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-07-19T19:17:12-07:00
Commit Message:
AGS: Refactored call_function to also use PluginMethod
Changed paths:
engines/ags/engine/script/cc_instance.cpp
engines/ags/engine/script/runtime_script_value.h
engines/ags/engine/script/script_runtime.cpp
engines/ags/engine/script/script_runtime.h
engines/ags/plugins/plugin_base.h
diff --git a/engines/ags/engine/script/cc_instance.cpp b/engines/ags/engine/script/cc_instance.cpp
index 1eac5ae7f4..7c9ba407b8 100644
--- a/engines/ags/engine/script/cc_instance.cpp
+++ b/engines/ags/engine/script/cc_instance.cpp
@@ -989,10 +989,10 @@ int ccInstance::Run(int32_t curpc) {
if (next_call_needs_object) {
RuntimeScriptValue obj_rval = registers[SREG_OP];
obj_rval.DirectPtrObj();
- int_ret_val = call_function((Plugins::ScriptContainer *)reg1.Ptr, reg1.methodName,
+ int_ret_val = call_function(reg1.pluginMethod(),
&obj_rval, num_args_to_func, func_callstack.GetHead() + 1);
} else {
- int_ret_val = call_function((Plugins::ScriptContainer *)reg1.Ptr, reg1.methodName,
+ int_ret_val = call_function(reg1.pluginMethod(),
nullptr, num_args_to_func, func_callstack.GetHead() + 1);
}
diff --git a/engines/ags/engine/script/runtime_script_value.h b/engines/ags/engine/script/runtime_script_value.h
index cd0301973e..60c49de367 100644
--- a/engines/ags/engine/script/runtime_script_value.h
+++ b/engines/ags/engine/script/runtime_script_value.h
@@ -331,6 +331,9 @@ public:
return rval;
}
+ Plugins::PluginMethod pluginMethod() const {
+ return Plugins::PluginMethod((Plugins::PluginBase *)Ptr, methodName);
+ }
// Helper functions for reading or writing values from/to
// object, referenced by this Runtime Value.
diff --git a/engines/ags/engine/script/script_runtime.cpp b/engines/ags/engine/script/script_runtime.cpp
index 09b5e58cfb..f4e13c8b5e 100644
--- a/engines/ags/engine/script/script_runtime.cpp
+++ b/engines/ags/engine/script/script_runtime.cpp
@@ -133,9 +133,10 @@ void ccSetDebugHook(new_line_hook_type jibble) {
_G(new_line_hook) = jibble;
}
-int call_function(Plugins::ScriptContainer *sc, const Common::String &name, const RuntimeScriptValue *object, int numparm, const RuntimeScriptValue *parms) {
- if (!sc) {
- cc_error("null script container pointer in call_function");
+int call_function(const Plugins::PluginMethod &method,
+ const RuntimeScriptValue *object, int numparm, const RuntimeScriptValue *parms) {
+ if (!method) {
+ cc_error("invalid method in call_function");
return -1;
}
if (numparm > 0 && !parms) {
@@ -179,15 +180,15 @@ int call_function(Plugins::ScriptContainer *sc, const Common::String &name, cons
params.push_back(parm_value[i]);
// Call the method
- (*sc).execMethod(name, params);
+ NumberPtr result = method(params);
// TODO: Though some script methods return pointers, the call_function only
// supports a 32-bit result. In case they're actually used by any game, the
// guard below will throw a wobbly if they're more than 32-bits
- if ((int64)params._result._ptr > 0xffffffff)
+ if (result._ptr > (void *)0xffffffff)
error("Uhandled 64-bit pointer result from plugin method call");
- return params._result;
+ return result;
}
}
diff --git a/engines/ags/engine/script/script_runtime.h b/engines/ags/engine/script/script_runtime.h
index 1895b00e0b..b8e8cf91e9 100644
--- a/engines/ags/engine/script/script_runtime.h
+++ b/engines/ags/engine/script/script_runtime.h
@@ -83,7 +83,7 @@ extern void ccSetScriptAliveTimer(int);
// reset the current while loop counter
extern void ccNotifyScriptStillAlive();
// for calling exported plugin functions old-style
-extern int call_function(Plugins::ScriptContainer *sc, const Common::String &name,
+extern int call_function(const Plugins::PluginMethod &method,
const RuntimeScriptValue *obj, int numparm, const RuntimeScriptValue *parms);
extern void nullfree(void *data); // in script/script_runtime
diff --git a/engines/ags/plugins/plugin_base.h b/engines/ags/plugins/plugin_base.h
index 4306d4ffe0..a65b9563db 100644
--- a/engines/ags/plugins/plugin_base.h
+++ b/engines/ags/plugins/plugin_base.h
@@ -196,31 +196,31 @@ public:
_sc(sc), _name(name) {
}
- bool isValid() const {
+ operator bool() const {
return _sc != nullptr;
}
- bool operator()(ScriptMethodParams ¶ms) {
+ NumberPtr operator()(ScriptMethodParams ¶ms) const {
_sc->execMethod(_name, params);
return params._result;
}
- NumberPtr operator()(intptr_t val1) {
+ NumberPtr operator()(intptr_t val1) const {
ScriptMethodParams params(val1);
_sc->execMethod(_name, params);
return params._result;
}
- NumberPtr operator()(intptr_t val1, intptr_t val2) {
+ NumberPtr operator()(intptr_t val1, intptr_t val2) const {
ScriptMethodParams params(val1, val2);
_sc->execMethod(_name, params);
return params._result;
}
- NumberPtr operator()(intptr_t val1, intptr_t val2, intptr_t val3) {
+ NumberPtr operator()(intptr_t val1, intptr_t val2, intptr_t val3) const {
ScriptMethodParams params(val1, val2, val3);
_sc->execMethod(_name, params);
return params._result;
}
- NumberPtr operator()(intptr_t val1, intptr_t val2, intptr_t val3, intptr_t val4) {
+ NumberPtr operator()(intptr_t val1, intptr_t val2, intptr_t val3, intptr_t val4) const {
ScriptMethodParams params(val1, val2, val3, val4);
_sc->execMethod(_name, params);
return params._result;
More information about the Scummvm-git-logs
mailing list