Beginnings of the "pass everything using a native type wrapper" console code.

- ConsoleValue class is now the base value class.
- ConsoleValueRef is now used to supply function parameters. Values are disposable.
- Script functions return values instead of just strings where possible.
- Variables can be disposable strings
- Bytecode changed

Fix the issues with console method parameters and fields which prevented missions from loading.
This commit is contained in:
James Urquhart 2012-09-23 09:59:48 +01:00
parent 394d87cd54
commit 38c8e52c1d
68 changed files with 1511 additions and 529 deletions

View file

@ -28,30 +28,26 @@
// Stupid globals not declared in a header
extern ExprEvalState gEvalState;
SimConsoleEvent::SimConsoleEvent(S32 argc, const char **argv, bool onObject)
SimConsoleEvent::SimConsoleEvent(S32 argc, ConsoleValueRef *argv, bool onObject)
{
mOnObject = onObject;
mArgc = argc;
U32 totalSize = 0;
S32 i;
for(i = 0; i < argc; i++)
totalSize += dStrlen(argv[i]) + 1;
totalSize += sizeof(char *) * argc;
mArgv = (char **) dMalloc(totalSize);
char *argBase = (char *) &mArgv[argc];
for(i = 0; i < argc; i++)
{
mArgv[i] = argBase;
dStrcpy(mArgv[i], argv[i]);
argBase += dStrlen(argv[i]) + 1;
mArgv = new ConsoleValueRef[argc];
for (int i=0; i<argc; i++) {
mArgv[i].value = new ConsoleValue();
mArgv[i].value->type = ConsoleValue::TypeInternalString;
mArgv[i].value->init();
mArgv[i].value->setStringValue((const char*)argv[i]);
}
}
SimConsoleEvent::~SimConsoleEvent()
{
dFree(mArgv);
for (int i=0; i<mArgc; i++) {
delete mArgv[i].value;
}
delete[] mArgv;
}
void SimConsoleEvent::process(SimObject* object)
@ -60,12 +56,14 @@ void SimConsoleEvent::process(SimObject* object)
// Con::printf("Executing schedule: %d", sequenceCount);
// #endif
if(mOnObject)
Con::execute(object, mArgc, const_cast<const char**>( mArgv ));
Con::execute(object, mArgc, mArgv );
else
{
// Grab the function name. If '::' doesn't exist, then the schedule is
// on a global function.
char* func = dStrstr( mArgv[0], (char*)"::" );
char funcName[256];
dStrncpy(funcName, (const char*)mArgv[0], 256);
char* func = dStrstr( funcName, (char*)"::" );
if( func )
{
// Set the first colon to NULL, so we can reference the namespace.
@ -77,18 +75,18 @@ void SimConsoleEvent::process(SimObject* object)
func += 2;
// Lookup the namespace and function entry.
Namespace* ns = Namespace::find( StringTable->insert( mArgv[0] ) );
Namespace* ns = Namespace::find( StringTable->insert( funcName ) );
if( ns )
{
Namespace::Entry* nse = ns->lookup( StringTable->insert( func ) );
if( nse )
// Execute.
nse->execute( mArgc, (const char**)mArgv, &gEvalState );
nse->execute( mArgc, mArgv, &gEvalState );
}
}
else
Con::execute(mArgc, const_cast<const char**>( mArgv ));
Con::execute(mArgc, mArgv );
}
}
@ -122,7 +120,7 @@ const char *SimConsoleThreadExecCallback::waitForResult()
//-----------------------------------------------------------------------------
SimConsoleThreadExecEvent::SimConsoleThreadExecEvent(S32 argc, const char **argv, bool onObject, SimConsoleThreadExecCallback *callback) :
SimConsoleThreadExecEvent::SimConsoleThreadExecEvent(S32 argc, ConsoleValueRef *argv, bool onObject, SimConsoleThreadExecCallback *callback) :
SimConsoleEvent(argc, argv, onObject), cb(callback)
{
}
@ -131,9 +129,9 @@ void SimConsoleThreadExecEvent::process(SimObject* object)
{
const char *retVal;
if(mOnObject)
retVal = Con::execute(object, mArgc, const_cast<const char**>( mArgv ));
retVal = Con::execute(object, mArgc, mArgv);
else
retVal = Con::execute(mArgc, const_cast<const char**>( mArgv ));
retVal = Con::execute(mArgc, mArgv);
if(cb)
cb->handleCallback(retVal);