Lots of work on lua call interface, also improved makefiles

This commit is contained in:
2025-02-24 16:46:05 -05:00
parent 4023d19247
commit bed4f3e805
10 changed files with 1870 additions and 101 deletions

View File

@@ -13,6 +13,37 @@ static void CheckNotEmpty(const FlxStreamBuffer &sb) {
}
}
static constexpr uint64_t ParseNameAsToken(std::string_view str) {
uint64_t result = 0;
uint64_t maxint = uint64_t(-1);
// Leading zeros are not allowed.
if ((!str.empty()) && (str[0]=='0')) return 0;
for (int i = 0; i < int(str.size()); i++) {
char c = str[i];
uint64_t digit = 0;
if ((c >= '0') && (c <= '9')) {
digit = uint64_t(c - '0');
} else if ((c >= 'a') && (c <= 'z')) {
digit = uint64_t(c - 'a' + 10);
} else if ((c >= 'A') && (c <= 'Z')) {
digit = uint64_t(c - 'A' + 10);
} else {
return maxint;
}
// Multiply existing number by 36, then add the digit.
// We have two checks to prevent integer overflow.
if (result > (maxint / 36)) return 0;
result *= 36;
if (digit > (maxint - result)) return 0;
result += digit;
}
return result;
}
void UlxLuaCallLibrary::LuaCallBegin(UObject *context, const FString &cname, const FString &fname) {
AIntegrationGameModeBase *mode = AIntegrationGameModeBase::GetFromContext(context);
FlxStreamBuffer &sb = mode->LuaCallGetBuffer();
@@ -31,11 +62,17 @@ void UlxLuaCallLibrary::LuaCallAddStringParameter(UObject *context, const FStrin
}
void UlxLuaCallLibrary::LuaCallAddNameParameter(UObject *context, const FName &pname) {
FTCHARToUTF8 utf8str(pname.ToString());
std::string_view namestr(utf8str.Get(), utf8str.Length());
uint64_t tokvalue = ParseNameAsToken(namestr);
if ((tokvalue == 0) && !namestr.empty()) {
FatalBlueprintError(TEXT("Names passed to lua must be short, and must contain only lowercase and digits"));
}
AIntegrationGameModeBase *mode = AIntegrationGameModeBase::GetFromContext(context);
FlxStreamBuffer &sb = mode->LuaCallGetBuffer();
CheckNotEmpty(sb);
sb.write_simple_dynamic_tag(SimpleDynamicTag::STRING);
sb.write_fname(pname);
sb.write_simple_dynamic_tag(SimpleDynamicTag::TOKEN);
sb.write_string(namestr);
}
void UlxLuaCallLibrary::LuaCallAddFloatParameter(UObject *context, double pfloat) {
@@ -46,6 +83,13 @@ void UlxLuaCallLibrary::LuaCallAddFloatParameter(UObject *context, double pfloat
sb.write_double(pfloat);
}
void UlxLuaCallLibrary::LuaCallAddIntParameter(UObject *context, int value) {
AIntegrationGameModeBase *mode = AIntegrationGameModeBase::GetFromContext(context);
FlxStreamBuffer &sb = mode->LuaCallGetBuffer();
CheckNotEmpty(sb);
sb.write_simple_dynamic_tag(SimpleDynamicTag::NUMBER);
sb.write_double(value);
}
void UlxLuaCallLibrary::LuaCallAddVectorParameter(UObject *context, const FVector &pvector) {
AIntegrationGameModeBase *mode = AIntegrationGameModeBase::GetFromContext(context);
@@ -55,6 +99,15 @@ void UlxLuaCallLibrary::LuaCallAddVectorParameter(UObject *context, const FVecto
sb.write_fvector(pvector);
}
void UlxLuaCallLibrary::LuaCallAddVector2DParameter(UObject *context, const FVector2D &pvector) {
AIntegrationGameModeBase *mode = AIntegrationGameModeBase::GetFromContext(context);
FlxStreamBuffer &sb = mode->LuaCallGetBuffer();
CheckNotEmpty(sb);
sb.write_simple_dynamic_tag(SimpleDynamicTag::VECTOR);
sb.write_double(pvector.X);
sb.write_double(pvector.Y);
sb.write_double(0.0);
}
void UlxLuaCallLibrary::LuaCallAddBooleanParameter(UObject *context, bool pbool) {
AIntegrationGameModeBase *mode = AIntegrationGameModeBase::GetFromContext(context);