diff --git a/include/mgba/script/types.h b/include/mgba/script/types.h index af6d8f736..87953723a 100644 --- a/include/mgba/script/types.h +++ b/include/mgba/script/types.h @@ -686,6 +686,7 @@ struct mScriptValue* mScriptValueUnwrap(struct mScriptValue* val); const struct mScriptValue* mScriptValueUnwrapConst(const struct mScriptValue* val); struct mScriptValue* mScriptStringCreateFromUTF8(const char* string); +struct mScriptValue* mScriptStringCreateFromASCII(const char* string); struct mScriptValue* mScriptValueCreateFromUInt(uint32_t value); struct mScriptValue* mScriptValueCreateFromSInt(int32_t value); diff --git a/src/script/types.c b/src/script/types.c index 835128c5f..1152e28ef 100644 --- a/src/script/types.c +++ b/src/script/types.c @@ -7,6 +7,7 @@ #include #include +#include #include static void _allocList(struct mScriptValue*); @@ -738,9 +739,20 @@ struct mScriptValue* mScriptStringCreateFromUTF8(const char* string) { struct mScriptValue* val = mScriptValueAlloc(mSCRIPT_TYPE_MS_STR); struct mScriptString* internal = val->value.opaque; internal->size = strlen(string); + internal->length = utf8strlen(string); internal->buffer = strdup(string); return val; } + +struct mScriptValue* mScriptStringCreateFromASCII(const char* string) { + struct mScriptValue* val = mScriptValueAlloc(mSCRIPT_TYPE_MS_STR); + struct mScriptString* internal = val->value.opaque; + internal->size = strlen(string); + internal->length = strlen(string); + internal->buffer = latin1ToUtf8(string, internal->size + 1); + return val; +} + struct mScriptValue* mScriptValueCreateFromSInt(int32_t value) { struct mScriptValue* val = mScriptValueAlloc(mSCRIPT_TYPE_MS_S32); val->value.s32 = value;