From 304d8d1a4dd134b4927b3e8f76f0e2e510e8c786 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Thu, 19 May 2022 22:32:10 -0700 Subject: [PATCH] Scripting: More API cleanup --- include/mgba/core/scripting.h | 2 +- include/mgba/script/types.h | 11 +++- src/core/scripting.c | 115 ++++++++++++++++++++-------------- src/core/test/scripting.c | 11 ---- src/script/context.c | 6 +- src/script/engines/lua.c | 11 ++-- src/script/types.c | 89 +++++++++++++++----------- 7 files changed, 137 insertions(+), 108 deletions(-) diff --git a/include/mgba/core/scripting.h b/include/mgba/core/scripting.h index 7a38e55c6..6c0943e46 100644 --- a/include/mgba/core/scripting.h +++ b/include/mgba/core/scripting.h @@ -20,10 +20,10 @@ CXX_GUARD_START mLOG_DECLARE_CATEGORY(SCRIPT); struct mCore; -struct mLogger; struct mScriptTextBuffer; mSCRIPT_DECLARE_STRUCT(mCore); mSCRIPT_DECLARE_STRUCT(mLogger); +mSCRIPT_DECLARE_STRUCT(mScriptConsole); mSCRIPT_DECLARE_STRUCT(mScriptTextBuffer); struct mScriptBridge; diff --git a/include/mgba/script/types.h b/include/mgba/script/types.h index 27733143f..239772483 100644 --- a/include/mgba/script/types.h +++ b/include/mgba/script/types.h @@ -51,11 +51,11 @@ CXX_GUARD_START #define mSCRIPT_TYPE_FIELD_S64 s64 #define mSCRIPT_TYPE_FIELD_U64 u64 #define mSCRIPT_TYPE_FIELD_F64 f64 -#define mSCRIPT_TYPE_FIELD_STR opaque +#define mSCRIPT_TYPE_FIELD_STR string #define mSCRIPT_TYPE_FIELD_CHARP copaque #define mSCRIPT_TYPE_FIELD_PTR opaque -#define mSCRIPT_TYPE_FIELD_LIST opaque -#define mSCRIPT_TYPE_FIELD_TABLE opaque +#define mSCRIPT_TYPE_FIELD_LIST list +#define mSCRIPT_TYPE_FIELD_TABLE table #define mSCRIPT_TYPE_FIELD_WRAPPER opaque #define mSCRIPT_TYPE_FIELD_WEAKREF u32 #define mSCRIPT_TYPE_FIELD_S(STRUCT) opaque @@ -172,6 +172,9 @@ struct mScriptValue { double f64; void* opaque; const void* copaque; + struct mScriptString* string; + struct Table* table; + struct mScriptList* list; } value; }; @@ -270,6 +273,8 @@ void mScriptValueWrap(struct mScriptValue* val, struct mScriptValue* out); struct mScriptValue* mScriptValueUnwrap(struct mScriptValue* val); const struct mScriptValue* mScriptValueUnwrapConst(const struct mScriptValue* val); +struct mScriptValue* mScriptStringCreateEmpty(size_t size); +struct mScriptValue* mScriptStringCreateFromBytes(const void* string, size_t size); struct mScriptValue* mScriptStringCreateFromUTF8(const char* string); struct mScriptValue* mScriptStringCreateFromASCII(const char* string); struct mScriptValue* mScriptValueCreateFromUInt(uint32_t value); diff --git a/src/core/scripting.c b/src/core/scripting.c index 12ba0046a..b8ff9fb11 100644 --- a/src/core/scripting.c +++ b/src/core/scripting.c @@ -161,7 +161,8 @@ struct mScriptCoreAdapter { struct mScriptValue memory; }; -struct mScriptUILibrary { +struct mScriptConsole { + struct mLogger* logger; mScriptContextBufferFactory textBufferFactory; void* textBufferContext; }; @@ -201,12 +202,12 @@ static uint32_t mScriptMemoryAdapterRead32(struct mScriptMemoryAdapter* adapter, static struct mScriptValue* mScriptMemoryAdapterReadRange(struct mScriptMemoryAdapter* adapter, uint32_t address, uint32_t length) { CALCULATE_SEGMENT_INFO; - struct mScriptValue* value = mScriptValueAlloc(mSCRIPT_TYPE_MS_LIST); - struct mScriptList* list = value->value.opaque; + struct mScriptValue* value = mScriptStringCreateEmpty(length); + char* buffer = value->value.string->buffer; uint32_t i; for (i = 0; i < length; ++i, ++address) { CALCULATE_SEGMENT_ADDRESS; - *mScriptListAppend(list) = mSCRIPT_MAKE_U32(adapter->core->rawRead8(adapter->core, segmentAddress, segment)); + buffer[i] = adapter->core->rawRead8(adapter->core, segmentAddress, segment); } return value; } @@ -268,11 +269,11 @@ static struct mScriptValue* _mScriptCoreGetGameCode(const struct mCore* core) { } static struct mScriptValue* _mScriptCoreReadRange(struct mCore* core, uint32_t address, uint32_t length) { - struct mScriptValue* value = mScriptValueAlloc(mSCRIPT_TYPE_MS_LIST); - struct mScriptList* list = value->value.opaque; + struct mScriptValue* value = mScriptStringCreateEmpty(length); + char* buffer = value->value.string->buffer; uint32_t i; for (i = 0; i < length; ++i, ++address) { - *mScriptListAppend(list) = mSCRIPT_MAKE_U32(core->busRead8(core, address)); + buffer[i] = core->busRead8(core, address); } return value; } @@ -497,36 +498,70 @@ void mScriptContextDetachCore(struct mScriptContext* context) { mScriptContextRemoveGlobal(context, "emu"); } -void mScriptLog(struct mLogger* logger, struct mScriptString* msg) { - mLogExplicit(logger, _mLOG_CAT_SCRIPT, mLOG_INFO, "%s", msg->buffer); +static struct mScriptTextBuffer* _mScriptConsoleCreateBuffer(struct mScriptConsole* lib, const char* name) { + struct mScriptTextBuffer* buffer = lib->textBufferFactory(lib->textBufferContext); + buffer->init(buffer, name); + return buffer; } -void mScriptWarn(struct mLogger* logger, struct mScriptString* msg) { - mLogExplicit(logger, _mLOG_CAT_SCRIPT, mLOG_WARN, "%s", msg->buffer); +static void mScriptConsoleLog(struct mScriptConsole* console, struct mScriptString* msg) { + if (console->logger) { + mLogExplicit(console->logger, _mLOG_CAT_SCRIPT, mLOG_INFO, "%s", msg->buffer); + } else { + mLog(_mLOG_CAT_SCRIPT, mLOG_INFO, "%s", msg->buffer); + } } -void mScriptError(struct mLogger* logger, struct mScriptString* msg) { - mLogExplicit(logger, _mLOG_CAT_SCRIPT, mLOG_ERROR, "%s", msg->buffer); +static void mScriptConsoleWarn(struct mScriptConsole* console, struct mScriptString* msg) { + if (console->logger) { + mLogExplicit(console->logger, _mLOG_CAT_SCRIPT, mLOG_WARN, "%s", msg->buffer); + } else { + mLog(_mLOG_CAT_SCRIPT, mLOG_WARN, "%s", msg->buffer); + } } -mSCRIPT_DECLARE_STRUCT_VOID_METHOD(mLogger, log, mScriptLog, 1, STR, msg); -mSCRIPT_DECLARE_STRUCT_VOID_METHOD(mLogger, warn, mScriptWarn, 1, STR, msg); -mSCRIPT_DECLARE_STRUCT_VOID_METHOD(mLogger, error, mScriptError, 1, STR, msg); +static void mScriptConsoleError(struct mScriptConsole* console, struct mScriptString* msg) { + if (console->logger) { + mLogExplicit(console->logger, _mLOG_CAT_SCRIPT, mLOG_ERROR, "%s", msg->buffer); + } else { + mLog(_mLOG_CAT_SCRIPT, mLOG_WARN, "%s", msg->buffer); + } +} -mSCRIPT_DEFINE_STRUCT(mLogger) -mSCRIPT_DEFINE_STRUCT_METHOD(mLogger, log) -mSCRIPT_DEFINE_STRUCT_METHOD(mLogger, warn) -mSCRIPT_DEFINE_STRUCT_METHOD(mLogger, error) +mSCRIPT_DECLARE_STRUCT_VOID_METHOD(mScriptConsole, log, mScriptConsoleLog, 1, STR, msg); +mSCRIPT_DECLARE_STRUCT_VOID_METHOD(mScriptConsole, warn, mScriptConsoleWarn, 1, STR, msg); +mSCRIPT_DECLARE_STRUCT_VOID_METHOD(mScriptConsole, error, mScriptConsoleError, 1, STR, msg); +mSCRIPT_DECLARE_STRUCT_METHOD_WITH_DEFAULTS(mScriptConsole, S(mScriptTextBuffer), createBuffer, _mScriptConsoleCreateBuffer, 1, CHARP, name); + +mSCRIPT_DEFINE_STRUCT(mScriptConsole) + mSCRIPT_DEFINE_STRUCT_METHOD(mScriptConsole, log) + mSCRIPT_DEFINE_STRUCT_METHOD(mScriptConsole, warn) + mSCRIPT_DEFINE_STRUCT_METHOD(mScriptConsole, error) + mSCRIPT_DEFINE_STRUCT_METHOD(mScriptConsole, createBuffer) mSCRIPT_DEFINE_END; +mSCRIPT_DEFINE_STRUCT_BINDING_DEFAULTS(mScriptConsole, createBuffer) + mSCRIPT_MAKE_CHARP(NULL) +mSCRIPT_DEFINE_DEFAULTS_END; + void mScriptContextAttachLogger(struct mScriptContext* context, struct mLogger* logger) { - struct mScriptValue* value = mScriptValueAlloc(mSCRIPT_TYPE_MS_S(mLogger)); - value->value.opaque = logger; - mScriptContextSetGlobal(context, "console", value); + struct mScriptValue* value = mScriptContextEnsureGlobal(context, "console", mSCRIPT_TYPE_MS_S(mScriptConsole)); + struct mScriptConsole* console = value->value.opaque; + if (!console) { + console = calloc(1, sizeof(*console)); + value->value.opaque = console; + value->flags = mSCRIPT_VALUE_FLAG_FREE_BUFFER; + } + console->logger = logger; } void mScriptContextDetachLogger(struct mScriptContext* context) { - mScriptContextRemoveGlobal(context, "console"); + struct mScriptValue* value = mScriptContextGetGlobal(context, "console"); + if (!value) { + return; + } + struct mScriptConsole* console = value->value.opaque; + console->logger = mLogGetContext(); } mSCRIPT_DECLARE_STRUCT_VOID_D_METHOD(mScriptTextBuffer, deinit, 0); @@ -556,31 +591,15 @@ mSCRIPT_DEFINE_STRUCT(mScriptTextBuffer) mSCRIPT_DEFINE_STRUCT_METHOD(mScriptTextBuffer, setName) mSCRIPT_DEFINE_END; -struct mScriptTextBuffer* _mScriptUICreateBuffer(struct mScriptUILibrary* lib, const char* name) { - struct mScriptTextBuffer* buffer = lib->textBufferFactory(lib->textBufferContext); - buffer->init(buffer, name); - return buffer; -} - -mSCRIPT_DECLARE_STRUCT(mScriptUILibrary); -mSCRIPT_DECLARE_STRUCT_METHOD_WITH_DEFAULTS(mScriptUILibrary, S(mScriptTextBuffer), createBuffer, _mScriptUICreateBuffer, 1, CHARP, name); - -mSCRIPT_DEFINE_STRUCT(mScriptUILibrary) - mSCRIPT_DEFINE_STRUCT_METHOD(mScriptUILibrary, createBuffer) -mSCRIPT_DEFINE_END; - -mSCRIPT_DEFINE_STRUCT_BINDING_DEFAULTS(mScriptUILibrary, createBuffer) - mSCRIPT_MAKE_CHARP(NULL) -mSCRIPT_DEFINE_DEFAULTS_END; - void mScriptContextSetTextBufferFactory(struct mScriptContext* context, mScriptContextBufferFactory factory, void* cbContext) { - struct mScriptValue* value = mScriptContextEnsureGlobal(context, "ui", mSCRIPT_TYPE_MS_S(mScriptUILibrary)); - struct mScriptUILibrary* uiLib = value->value.opaque; - if (!uiLib) { - uiLib = calloc(1, sizeof(*uiLib)); - value->value.opaque = uiLib; + struct mScriptValue* value = mScriptContextEnsureGlobal(context, "console", mSCRIPT_TYPE_MS_S(mScriptConsole)); + struct mScriptConsole* console = value->value.opaque; + if (!console) { + console = calloc(1, sizeof(*console)); + console->logger = mLogGetContext(); + value->value.opaque = console; value->flags = mSCRIPT_VALUE_FLAG_FREE_BUFFER; } - uiLib->textBufferFactory = factory; - uiLib->textBufferContext = cbContext; + console->textBufferFactory = factory; + console->textBufferContext = cbContext; } diff --git a/src/core/test/scripting.c b/src/core/test/scripting.c index fd6dbc8ca..3d2b8c4fa 100644 --- a/src/core/test/scripting.c +++ b/src/core/test/scripting.c @@ -313,17 +313,6 @@ M_TEST_DEFINE(logging) { assert_string_equal(logger.error, "error"); mScriptContextDetachLogger(&context); - - LOAD_PROGRAM( - "assert(not console)\n" - ); - assert_true(lua->run(lua)); - - LOAD_PROGRAM( - "a:log(\"l2\")\n" - ); - assert_false(lua->run(lua)); - mScriptTestLoggerDeinit(&logger); mScriptContextDeinit(&context); } diff --git a/src/script/context.c b/src/script/context.c index b3ec04ffd..af7fef3b8 100644 --- a/src/script/context.c +++ b/src/script/context.c @@ -195,10 +195,10 @@ void mScriptContextTriggerCallback(struct mScriptContext* context, const char* c return; } size_t i; - for (i = 0; i < mScriptListSize(list->value.opaque); ++i) { + for (i = 0; i < mScriptListSize(list->value.list); ++i) { struct mScriptFrame frame; mScriptFrameInit(&frame); - struct mScriptValue* fn = mScriptListGetPointer(list->value.opaque, i); + struct mScriptValue* fn = mScriptListGetPointer(list->value.list, i); if (fn->type->base == mSCRIPT_TYPE_WRAPPER) { fn = mScriptValueUnwrap(fn); } @@ -216,7 +216,7 @@ void mScriptContextAddCallback(struct mScriptContext* context, const char* callb list = mScriptValueAlloc(mSCRIPT_TYPE_MS_LIST); HashTableInsert(&context->callbacks, callback, list); } - mScriptValueWrap(fn, mScriptListAppend(list->value.opaque)); + mScriptValueWrap(fn, mScriptListAppend(list->value.list)); } void mScriptContextExportConstants(struct mScriptContext* context, const char* nspace, struct mScriptKVPair* constants) { diff --git a/src/script/engines/lua.c b/src/script/engines/lua.c index f33e0ef4c..90005eed6 100644 --- a/src/script/engines/lua.c +++ b/src/script/engines/lua.c @@ -216,6 +216,8 @@ struct mScriptValue* _luaCoerce(struct mScriptEngineContextLua* luaContext) { return NULL; } + size_t size; + const void* buffer; struct mScriptValue* value = NULL; switch (lua_type(luaContext->lua, -1)) { case LUA_TNUMBER: @@ -234,7 +236,8 @@ struct mScriptValue* _luaCoerce(struct mScriptEngineContextLua* luaContext) { value->value.s32 = lua_toboolean(luaContext->lua, -1); break; case LUA_TSTRING: - value = mScriptStringCreateFromUTF8(lua_tostring(luaContext->lua, -1)); + buffer = lua_tolstring(luaContext->lua, -1, &size); + value = mScriptStringCreateFromBytes(buffer, size); mScriptValueWrap(value, mScriptListAppend(&luaContext->d.context->refPool)); mScriptValueDeref(value); break; @@ -311,7 +314,7 @@ bool _luaWrap(struct mScriptEngineContextLua* luaContext, struct mScriptValue* v } break; case mSCRIPT_TYPE_STRING: - lua_pushstring(luaContext->lua, ((struct mScriptString*) value->value.opaque)->buffer); + lua_pushlstring(luaContext->lua, value->value.string->buffer, value->value.string->size); mScriptValueDeref(value); break; case mSCRIPT_TYPE_LIST: @@ -753,7 +756,7 @@ int _luaGetList(lua_State* lua) { luaL_traceback(lua, lua, "Invalid list", 1); lua_error(lua); } - struct mScriptList* list = obj->value.opaque; + struct mScriptList* list = obj->value.list; // Lua indexes from 1 if (index < 1) { @@ -786,7 +789,7 @@ static int _luaLenList(lua_State* lua) { luaL_traceback(lua, lua, "Invalid list", 1); lua_error(lua); } - struct mScriptList* list = obj->value.opaque; + struct mScriptList* list = obj->value.list; lua_pushinteger(lua, mScriptListSize(list)); return 1; } diff --git a/src/script/types.c b/src/script/types.c index 297a2b3b8..f4a268ac4 100644 --- a/src/script/types.c +++ b/src/script/types.c @@ -182,6 +182,7 @@ const struct mScriptType mSTCharPtr = { .hash = _hashString, .equal = _charpEqual, .cast = _stringCast, + .isConst = true, }; const struct mScriptType mSTList = { @@ -223,24 +224,24 @@ const struct mScriptType mSTWeakref = { DEFINE_VECTOR(mScriptList, struct mScriptValue) void _allocList(struct mScriptValue* val) { - val->value.opaque = malloc(sizeof(struct mScriptList)); - mScriptListInit(val->value.opaque, 0); + val->value.list = malloc(sizeof(struct mScriptList)); + mScriptListInit(val->value.list, 0); } void _freeList(struct mScriptValue* val) { size_t i; - for (i = 0; i < mScriptListSize(val->value.opaque); ++i) { - struct mScriptValue* unwrapped = mScriptValueUnwrap(mScriptListGetPointer(val->value.opaque, i)); + for (i = 0; i < mScriptListSize(val->value.list); ++i) { + struct mScriptValue* unwrapped = mScriptValueUnwrap(mScriptListGetPointer(val->value.list, i)); if (unwrapped) { mScriptValueDeref(unwrapped); } } - mScriptListDeinit(val->value.opaque); - free(val->value.opaque); + mScriptListDeinit(val->value.list); + free(val->value.list); } void _allocTable(struct mScriptValue* val) { - val->value.opaque = malloc(sizeof(struct Table)); + val->value.table = malloc(sizeof(struct Table)); struct TableFunctions funcs = { .deinitializer = _deinitTableValue, .hash = _valHash, @@ -248,12 +249,12 @@ void _allocTable(struct mScriptValue* val) { .ref = _valRef, .deref = _valDeref }; - HashTableInitCustom(val->value.opaque, 0, &funcs); + HashTableInitCustom(val->value.table, 0, &funcs); } void _freeTable(struct mScriptValue* val) { - HashTableDeinit(val->value.opaque); - free(val->value.opaque); + HashTableDeinit(val->value.table); + free(val->value.table); } void _deinitTableValue(void* val) { @@ -264,11 +265,11 @@ static void _allocString(struct mScriptValue* val) { struct mScriptString* string = calloc(1, sizeof(*string)); string->size = 0; string->buffer = NULL; - val->value.opaque = string; + val->value.string = string; } static void _freeString(struct mScriptValue* val) { - struct mScriptString* string = val->value.opaque; + struct mScriptString* string = val->value.string; if (string->size) { free(string->buffer); } @@ -287,7 +288,7 @@ static bool _stringCast(const struct mScriptValue* in, const struct mScriptType* out->type = type; out->refs = mSCRIPT_VALUE_UNREF; out->flags = 0; - out->value.opaque = ((struct mScriptString*) in->value.opaque)->buffer; + out->value.opaque = in->value.string->buffer; return true; } return false; @@ -297,7 +298,7 @@ static uint32_t _hashString(const struct mScriptValue* val) { const char* buffer = 0; size_t size = 0; if (val->type == &mSTString) { - struct mScriptString* string = val->value.opaque; + struct mScriptString* string = val->value.string; buffer = string->buffer; size = string->size; } else if (val->type == &mSTCharPtr) { @@ -642,7 +643,7 @@ bool _charpEqual(const struct mScriptValue* a, const struct mScriptValue* b) { valB = b->value.opaque; lenB = strlen(valB); } else if (b->type == &mSTString) { - struct mScriptString* stringB = b->value.opaque; + struct mScriptString* stringB = b->value.string; valB = stringB->buffer; lenB = stringB->size; } else { @@ -657,7 +658,7 @@ bool _charpEqual(const struct mScriptValue* a, const struct mScriptValue* b) { } bool _stringEqual(const struct mScriptValue* a, const struct mScriptValue* b) { - struct mScriptString* stringA = a->value.opaque; + struct mScriptString* stringA = a->value.string; const char* valA = stringA->buffer; const char* valB; size_t lenA = stringA->size; @@ -669,7 +670,7 @@ bool _stringEqual(const struct mScriptValue* a, const struct mScriptValue* b) { valB = b->value.opaque; lenB = strlen(valB); } else if (b->type == &mSTString) { - struct mScriptString* stringB = b->value.opaque; + struct mScriptString* stringB = b->value.string; valB = stringB->buffer; lenB = stringB->size; } else { @@ -757,9 +758,30 @@ const struct mScriptValue* mScriptValueUnwrapConst(const struct mScriptValue* va return NULL; } -struct mScriptValue* mScriptStringCreateFromUTF8(const char* string) { +struct mScriptValue* mScriptStringCreateEmpty(size_t size) { struct mScriptValue* val = mScriptValueAlloc(mSCRIPT_TYPE_MS_STR); struct mScriptString* internal = val->value.opaque; + internal->size = size; + internal->length = 0; + internal->buffer = malloc(size + 1); + memset(internal->buffer, 0, size + 1); + return val; +} + +struct mScriptValue* mScriptStringCreateFromBytes(const void* string, size_t size) { + struct mScriptValue* val = mScriptValueAlloc(mSCRIPT_TYPE_MS_STR); + struct mScriptString* internal = val->value.opaque; + internal->size = size; + internal->length = 0; + internal->buffer = malloc(size + 1); + memcpy(internal->buffer, string, size); + internal->buffer[size] = '\0'; + return val; +} + +struct mScriptValue* mScriptStringCreateFromUTF8(const char* string) { + struct mScriptValue* val = mScriptValueAlloc(mSCRIPT_TYPE_MS_STR); + struct mScriptString* internal = val->value.string; internal->size = strlen(string); internal->length = utf8strlen(string); internal->buffer = strdup(string); @@ -768,7 +790,7 @@ struct mScriptValue* mScriptStringCreateFromUTF8(const char* string) { struct mScriptValue* mScriptStringCreateFromASCII(const char* string) { struct mScriptValue* val = mScriptValueAlloc(mSCRIPT_TYPE_MS_STR); - struct mScriptString* internal = val->value.opaque; + struct mScriptString* internal = val->value.string; internal->size = strlen(string); internal->length = strlen(string); internal->buffer = latin1ToUtf8(string, internal->size + 1); @@ -794,9 +816,8 @@ bool mScriptTableInsert(struct mScriptValue* table, struct mScriptValue* key, st if (!key->type->hash) { return false; } - struct Table* t = table->value.opaque; mScriptValueRef(value); - HashTableInsertCustom(t, key, value); + HashTableInsertCustom(table->value.table, key, value); return true; } @@ -807,8 +828,7 @@ bool mScriptTableRemove(struct mScriptValue* table, struct mScriptValue* key) { if (!key->type->hash) { return false; } - struct Table* t = table->value.opaque; - HashTableRemoveCustom(t, key); + HashTableRemoveCustom(table->value.table, key); return true; } @@ -822,16 +842,14 @@ struct mScriptValue* mScriptTableLookup(struct mScriptValue* table, struct mScri if (!key->type->hash) { return false; } - struct Table* t = table->value.opaque; - return HashTableLookupCustom(t, key); + return HashTableLookupCustom(table->value.table, key); } bool mScriptTableClear(struct mScriptValue* table) { if (table->type != mSCRIPT_TYPE_MS_TABLE) { return false; } - struct Table* t = table->value.opaque; - HashTableClear(t); + HashTableClear(table->value.table); return true; } @@ -842,8 +860,7 @@ bool mScriptTableIteratorStart(struct mScriptValue* table, struct TableIterator* if (table->type != mSCRIPT_TYPE_MS_TABLE) { return false; } - struct Table* t = table->value.opaque; - return HashTableIteratorStart(t, iter); + return HashTableIteratorStart(table->value.table, iter); } bool mScriptTableIteratorNext(struct mScriptValue* table, struct TableIterator* iter) { @@ -853,8 +870,7 @@ bool mScriptTableIteratorNext(struct mScriptValue* table, struct TableIterator* if (table->type != mSCRIPT_TYPE_MS_TABLE) { return false; } - struct Table* t = table->value.opaque; - return HashTableIteratorNext(t, iter); + return HashTableIteratorNext(table->value.table, iter); } struct mScriptValue* mScriptTableIteratorGetKey(struct mScriptValue* table, struct TableIterator* iter) { @@ -864,8 +880,7 @@ struct mScriptValue* mScriptTableIteratorGetKey(struct mScriptValue* table, stru if (table->type != mSCRIPT_TYPE_MS_TABLE) { return NULL; } - struct Table* t = table->value.opaque; - return HashTableIteratorGetCustomKey(t, iter); + return HashTableIteratorGetCustomKey(table->value.table, iter); } struct mScriptValue* mScriptTableIteratorGetValue(struct mScriptValue* table, struct TableIterator* iter) { @@ -875,8 +890,7 @@ struct mScriptValue* mScriptTableIteratorGetValue(struct mScriptValue* table, st if (table->type != mSCRIPT_TYPE_MS_TABLE) { return NULL; } - struct Table* t = table->value.opaque; - return HashTableIteratorGetValue(t, iter); + return HashTableIteratorGetValue(table->value.table, iter); } bool mScriptTableIteratorLookup(struct mScriptValue* table, struct TableIterator* iter, struct mScriptValue* key) { @@ -886,8 +900,7 @@ bool mScriptTableIteratorLookup(struct mScriptValue* table, struct TableIterator if (table->type != mSCRIPT_TYPE_MS_TABLE) { return false; } - struct Table* t = table->value.opaque; - return HashTableIteratorLookupCustom(t, iter, key); + return HashTableIteratorLookupCustom(table->value.table, iter, key); } void mScriptFrameInit(struct mScriptFrame* frame) { @@ -1053,7 +1066,7 @@ static bool _accessRawMember(struct mScriptClassMember* member, void* raw, bool val->refs = mSCRIPT_VALUE_UNREF; val->flags = 0; val->type = mSCRIPT_TYPE_MS_WRAPPER; - val->value.opaque = raw; + val->value.table = raw; break; case mSCRIPT_TYPE_FUNCTION: val->refs = mSCRIPT_VALUE_UNREF;