Integrate new CInterface into the engine-console

This commit is contained in:
Lukas Joergensen 2018-04-21 10:24:41 +02:00
parent 8cdad51639
commit cd06f569fa
6 changed files with 67 additions and 8 deletions

View file

@ -61,6 +61,7 @@
// For the TickMs define... fix this for T2D...
#include "T3D/gameBase/processList.h"
#include "cinterface/cinterface.h"
#ifdef TORQUE_ENABLE_VFS
#include "platform/platformVFS.h"
@ -443,6 +444,11 @@ bool StandardMainLoop::handleCommandLine( S32 argc, const char **argv )
// directly because the resource system restricts
// access to the "root" directory.
bool foundExternalMain = false;
CInterface::CallMain(&foundExternalMain);
if (foundExternalMain)
return true;
#ifdef TORQUE_ENABLE_VFS
Zip::ZipArchive *vfs = openEmbeddedVFSArchive();
bool useVFS = vfs != NULL;

View file

@ -42,12 +42,13 @@ namespace Sim
return Sim::getDataBlockGroup()->findObject(StringTable->insert(pName));
}
DefineNewEngineFunction(WrapObject, SimObjectPtr<SimObject>*, (SimObject* pObject), , "")
// EngineAPI doesn't work with SimObjectPtr
TORQUE_API SimObjectPtr<SimObject>* fnWrapObject (SimObject* pObject)
{
return new SimObjectPtr<SimObject>(pObject);
}
DefineNewEngineFunction(DeleteObjectPtr, void, (SimObjectPtr<SimObject>* pObjectPtr), , "")
TORQUE_API void fnDeleteObjectPtr(SimObjectPtr<SimObject>* pObjectPtr)
{
delete pObjectPtr;
}

View file

@ -20,8 +20,6 @@
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "c_simobjectInterface.h"
#include "console/engineAPI.h"
#include "console/simObject.h"

View file

@ -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))
{
@ -2152,11 +2163,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

View file

@ -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;

View file

@ -455,6 +455,15 @@ bool ModuleManager::loadModuleGroup( const char* pModuleGroup )
moduleGroup, pLoadReadyModuleDefinition->getModuleId(), pLoadReadyModuleDefinition->getVersionId(), pLoadReadyModuleDefinition->getModuleScriptFilePath() );
}
}
else
{
// Is the create method available?
if (pScopeSet->isMethod(pLoadReadyModuleDefinition->getCreateFunction()))
{
// Yes, so call the create method.
Con::executef(pScopeSet, pLoadReadyModuleDefinition->getCreateFunction());
}
}
// Raise notifications.
raiseModulePostLoadNotifications( pLoadReadyModuleDefinition );