mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-12 19:31:41 +00:00
commit
cbc09534e4
15 changed files with 639 additions and 990 deletions
|
|
@ -37,6 +37,7 @@
|
|||
#include "core/strings/stringUnit.h"
|
||||
#include "console/console.h"
|
||||
#include "console/consoleInternal.h"
|
||||
#include "cinterface/cinterface.h"
|
||||
|
||||
//#define TORQUE_VALIDATE_STACK
|
||||
|
||||
|
|
@ -2023,7 +2024,7 @@ OPCodeReturn CodeInterpreter::op_callfunc_resolve(U32 &ip)
|
|||
|
||||
// Try to look it up.
|
||||
mNSEntry = Namespace::find(fnNamespace)->lookup(fnName);
|
||||
if (!mNSEntry)
|
||||
if (!CInterface::GetCInterface().isMethod(fnNamespace, fnName) && !mNSEntry)
|
||||
{
|
||||
ip += 5;
|
||||
Con::warnf(ConsoleLogEntry::General,
|
||||
|
|
@ -2051,6 +2052,7 @@ OPCodeReturn CodeInterpreter::op_callfunc(U32 &ip)
|
|||
|
||||
U32 *code = mCodeBlock->code;
|
||||
|
||||
StringTableEntry fnNamespace = CodeToSTE(mCodeBlock->code, ip + 2);
|
||||
StringTableEntry fnName = CodeToSTE(code, ip);
|
||||
|
||||
//if this is called from inside a function, append the ip and codeptr
|
||||
|
|
@ -2068,10 +2070,16 @@ OPCodeReturn CodeInterpreter::op_callfunc(U32 &ip)
|
|||
const char *componentReturnValue = "";
|
||||
Namespace *ns = NULL;
|
||||
|
||||
bool cFunctionRes = false;
|
||||
const char* cRetRes = NULL;
|
||||
|
||||
if (callType == FuncCallExprNode::FunctionCall)
|
||||
{
|
||||
if (!mNSEntry)
|
||||
mNSEntry = Namespace::global()->lookup(fnName);
|
||||
|
||||
StringStackWrapper args(mCallArgc, mCallArgv);
|
||||
cRetRes = CInterface::GetCInterface().CallFunction(fnNamespace, fnName, args.argv, args.argc, &cFunctionRes);
|
||||
}
|
||||
else if (callType == FuncCallExprNode::MethodCall)
|
||||
{
|
||||
|
|
@ -2102,6 +2110,9 @@ OPCodeReturn CodeInterpreter::op_callfunc(U32 &ip)
|
|||
mNSEntry = ns->lookup(fnName);
|
||||
else
|
||||
mNSEntry = NULL;
|
||||
|
||||
StringStackWrapper args(mCallArgc, mCallArgv);
|
||||
cRetRes = CInterface::GetCInterface().CallMethod(gEvalState.thisObject, fnName, args.argv, args.argc, &cFunctionRes);
|
||||
}
|
||||
else // it's a ParentCall
|
||||
{
|
||||
|
|
@ -2128,7 +2139,7 @@ OPCodeReturn CodeInterpreter::op_callfunc(U32 &ip)
|
|||
nsUsage = mNSEntry->mUsage;
|
||||
routingId = 0;
|
||||
}
|
||||
if (!mNSEntry || mExec.noCalls)
|
||||
if (!cFunctionRes && (!mNSEntry || mExec.noCalls))
|
||||
{
|
||||
if (!mExec.noCalls && !(routingId == MethodOnComponent))
|
||||
{
|
||||
|
|
@ -2167,11 +2178,19 @@ OPCodeReturn CodeInterpreter::op_callfunc(U32 &ip)
|
|||
|
||||
// ConsoleFunctionType is for any function defined by script.
|
||||
// Any 'callback' type is an engine function that is exposed to script.
|
||||
if (mNSEntry->mType == Namespace::Entry::ConsoleFunctionType)
|
||||
if (mNSEntry->mType == Namespace::Entry::ConsoleFunctionType
|
||||
|| cFunctionRes)
|
||||
{
|
||||
ConsoleValueRef ret;
|
||||
if (mNSEntry->mFunctionOffset)
|
||||
if (cFunctionRes)
|
||||
{
|
||||
StringStackConsoleWrapper retVal(1, &cRetRes);
|
||||
ret = retVal.argv[0];
|
||||
}
|
||||
else if (mNSEntry->mFunctionOffset)
|
||||
{
|
||||
ret = mNSEntry->mCode->exec(mNSEntry->mFunctionOffset, fnName, mNSEntry->mNamespace, mCallArgc, mCallArgv, false, mNSEntry->mPackage);
|
||||
}
|
||||
|
||||
STR.popFrame();
|
||||
// Functions are assumed to return strings, so look ahead to see if we can skip the conversion
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@
|
|||
#include <stdarg.h>
|
||||
#include "platform/threads/mutex.h"
|
||||
#include "core/util/journal/journal.h"
|
||||
#include "cinterface/cinterface.h"
|
||||
|
||||
extern StringStack STR;
|
||||
extern ConsoleValueStack CSTK;
|
||||
|
|
@ -1488,6 +1489,18 @@ ConsoleValueRef evaluatef(const char* string, ...)
|
|||
// Internal execute for global function which does not save the stack
|
||||
ConsoleValueRef _internalExecute(S32 argc, ConsoleValueRef argv[])
|
||||
{
|
||||
const char** argv_str = static_cast<const char**>(malloc((argc - 1) * sizeof(char *)));
|
||||
for (int i = 0; i < argc - 1; i++)
|
||||
{
|
||||
argv_str[i] = argv[i + 1];
|
||||
}
|
||||
bool result;
|
||||
const char* methodRes = CInterface::CallFunction(NULL, argv[0], argv_str, argc - 1, &result);
|
||||
if (result)
|
||||
{
|
||||
return ConsoleValueRef::fromValue(CSTK.pushString(methodRes));
|
||||
}
|
||||
|
||||
Namespace::Entry *ent;
|
||||
StringTableEntry funcName = StringTable->insert(argv[0]);
|
||||
ent = Namespace::global()->lookup(funcName);
|
||||
|
|
@ -1559,6 +1572,18 @@ ConsoleValueRef _internalExecute(SimObject *object, S32 argc, ConsoleValueRef ar
|
|||
}
|
||||
}
|
||||
|
||||
const char** argv_str = static_cast<const char**>(malloc((argc - 2) * sizeof(char *)));
|
||||
for (int i = 0; i < argc - 2; i++)
|
||||
{
|
||||
argv_str[i] = argv[i + 2];
|
||||
}
|
||||
bool result;
|
||||
const char* methodRes = CInterface::CallMethod(object, argv[0], argv_str, argc - 2, &result);
|
||||
if (result)
|
||||
{
|
||||
return ConsoleValueRef::fromValue(CSTK.pushString(methodRes));
|
||||
}
|
||||
|
||||
if(object->getNamespace())
|
||||
{
|
||||
U32 ident = object->getId();
|
||||
|
|
@ -1655,6 +1680,7 @@ inline ConsoleValueRef _executef(S32 checkArgc, S32 argc, ConsoleValueRef *argv)
|
|||
//------------------------------------------------------------------------------
|
||||
bool isFunction(const char *fn)
|
||||
{
|
||||
if (CInterface::isMethod(NULL, fn)) return true;
|
||||
const char *string = StringTable->lookup(fn);
|
||||
if(!string)
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -455,7 +455,6 @@ class SimObject: public ConsoleObject, public TamlCallbacks
|
|||
{
|
||||
T* object = new T;
|
||||
object->incRefCount();
|
||||
object->registerObject();
|
||||
return object;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue