- scriptified Strife's coins.

- added a String class to allow attaching methods to the builtin string type. This works by checking if the left side of the member accessor is a string and just replacing the tyoe in this one place, all the rest is automatic.
This commit is contained in:
Christoph Oelckers 2016-11-28 18:15:18 +01:00
commit 9064a5b0ac
17 changed files with 222 additions and 34 deletions

View file

@ -5766,9 +5766,11 @@ FxExpression *FxMemberIdentifier::Resolve(FCompileContext& ctx)
// allow accessing the color channels by mapping the type to a matching struct which defines them.
if (Object->ValueType == TypeColor)
{
Object->ValueType = TypeColorStruct;
}
if (Object->ValueType->IsKindOf(RUNTIME_CLASS(PPointer)))
else if (Object->ValueType->IsKindOf(RUNTIME_CLASS(PPointer)))
{
auto ptype = static_cast<PPointer *>(Object->ValueType)->PointedType;
if (ptype->IsKindOf(RUNTIME_CLASS(PStruct)))
@ -7306,6 +7308,12 @@ FxExpression *FxMemberFunctionCall::Resolve(FCompileContext& ctx)
}
}
if (Self->ValueType == TypeString)
{
// same for String methods. It also uses a hidden struct type to define them.
Self->ValueType = TypeStringStruct;
}
if (Self->ValueType->IsKindOf(RUNTIME_CLASS(PPointer)))
{
auto ptype = static_cast<PPointer *>(Self->ValueType)->PointedType;
@ -7876,8 +7884,16 @@ ExpEmit FxVMFunctionCall::Emit(VMFunctionBuilder *build)
{
assert(Self != nullptr);
selfemit = Self->Emit(build);
assert(selfemit.RegType == REGT_POINTER);
build->Emit(OP_PARAM, 0, selfemit.RegType, selfemit.RegNum);
assert((selfemit.RegType == REGT_POINTER) || (selfemit.Fixed && selfemit.Target));
if (selfemit.Fixed && selfemit.Target)
{
// Address of a local variable.
build->Emit(OP_PARAM, 0, selfemit.RegType | REGT_ADDROF, selfemit.RegNum);
}
else
{
build->Emit(OP_PARAM, 0, selfemit.RegType, selfemit.RegNum);
}
count += 1;
if (Function->Variants[0].Flags & VARF_Action)
{

View file

@ -46,6 +46,8 @@
#include "p_maputl.h"
#include "gi.h"
#include "p_terrain.h"
#include "gstrings.h"
#include "zstring.h"
static TArray<FPropertyInfo*> properties;
static TArray<AFuncDesc> AFTable;
@ -826,3 +828,19 @@ DEFINE_ACTION_FUNCTION(DObject, GameType)
PARAM_PROLOGUE;
ACTION_RETURN_INT(gameinfo.gametype);
}
DEFINE_ACTION_FUNCTION(FStringTable, Localize)
{
PARAM_PROLOGUE;
PARAM_STRING(label);
ACTION_RETURN_STRING(GStrings(label));
}
DEFINE_ACTION_FUNCTION(FString, Replace)
{
PARAM_SELF_STRUCT_PROLOGUE(FString);
PARAM_STRING(s1);
PARAM_STRING(s2);
self->Substitute(*s1, *s2);
return 0;
}

View file

@ -289,6 +289,10 @@ void VMDisasm(FILE *out, const VMOP *code, int codesize, const VMScriptFunction
a &= CMP_CHECK | CMP_APPROX;
cmp = true;
}
if (code[i].op == OP_PARAM && code[i].b & REGT_ADDROF)
{
name = "parama";
}
if (cmp)
{ // Comparison instruction. Modify name for inverted test.
if (!(a & CMP_CHECK))