Scripting: Basic void type bringup

This commit is contained in:
Vicki Pfau 2022-06-16 23:40:11 -07:00
parent 0b2cfb505f
commit 840e2806b5
3 changed files with 13 additions and 0 deletions

View File

@ -174,6 +174,8 @@ extern const struct mScriptType mSTWeakref;
extern const struct mScriptType mSTStringWrapper;
extern const struct mScriptType mSTListWrapper;
extern struct mScriptValue mScriptValueNull;
struct mScriptType;
struct mScriptValue {
const struct mScriptType* type;

View File

@ -320,6 +320,9 @@ struct mScriptValue* _luaCoerce(struct mScriptEngineContextLua* luaContext, bool
const void* buffer;
struct mScriptValue* value = NULL;
switch (lua_type(luaContext->lua, -1)) {
case LUA_TNIL:
value = &mScriptValueNull;
break;
case LUA_TNUMBER:
#if LUA_VERSION_NUM >= 503
if (lua_isinteger(luaContext->lua, -1)) {
@ -398,6 +401,9 @@ bool _luaWrap(struct mScriptEngineContextLua* luaContext, struct mScriptValue* v
bool ok = true;
struct mScriptValue* newValue;
switch (value->type->base) {
case mSCRIPT_TYPE_VOID:
lua_pushnil(luaContext->lua);
break;
case mSCRIPT_TYPE_SINT:
if (value->type->size <= 4) {
lua_pushinteger(luaContext->lua, value->value.s32);

View File

@ -239,6 +239,11 @@ const struct mScriptType mSTWeakref = {
.hash = NULL,
};
struct mScriptValue mScriptValueNull = {
.type = &mSTVoid,
.refs = mSCRIPT_VALUE_UNREF
};
DEFINE_VECTOR(mScriptList, struct mScriptValue)
void _allocList(struct mScriptValue* val) {