Add support for LuaToken to the LuaCall unreal pipeline
This commit is contained in:
@@ -30,6 +30,13 @@ void UlxLuaCallLibrary::LuaCallAddStringParameter(UObject *context, const FStrin
|
|||||||
sb.write_string(pstring);
|
sb.write_string(pstring);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UlxLuaCallLibrary::LuaCallAddNameParameter(UObject *context, const FName &pname) {
|
||||||
|
AIntegrationGameModeBase *mode = AIntegrationGameModeBase::GetFromContext(context);
|
||||||
|
FlxStreamBuffer &sb = mode->LuaCallGetBuffer();
|
||||||
|
CheckNotEmpty(sb);
|
||||||
|
sb.write_simple_dynamic_tag(SimpleDynamicTag::STRING);
|
||||||
|
sb.write_fname(pname);
|
||||||
|
}
|
||||||
|
|
||||||
void UlxLuaCallLibrary::LuaCallAddFloatParameter(UObject *context, double pfloat) {
|
void UlxLuaCallLibrary::LuaCallAddFloatParameter(UObject *context, double pfloat) {
|
||||||
AIntegrationGameModeBase *mode = AIntegrationGameModeBase::GetFromContext(context);
|
AIntegrationGameModeBase *mode = AIntegrationGameModeBase::GetFromContext(context);
|
||||||
@@ -98,6 +105,7 @@ ELpxSimpleDynamicTag UlxLuaCallLibrary::LuaCallNextResultType(UObject *context)
|
|||||||
sb.unread_to(total_reads);
|
sb.unread_to(total_reads);
|
||||||
switch (tag) {
|
switch (tag) {
|
||||||
case SimpleDynamicTag::STRING: return ELpxSimpleDynamicTag::String;
|
case SimpleDynamicTag::STRING: return ELpxSimpleDynamicTag::String;
|
||||||
|
case SimpleDynamicTag::TOKEN: return ELpxSimpleDynamicTag::Name;
|
||||||
case SimpleDynamicTag::NUMBER: return ELpxSimpleDynamicTag::Float;
|
case SimpleDynamicTag::NUMBER: return ELpxSimpleDynamicTag::Float;
|
||||||
case SimpleDynamicTag::VECTOR: return ELpxSimpleDynamicTag::Vector;
|
case SimpleDynamicTag::VECTOR: return ELpxSimpleDynamicTag::Vector;
|
||||||
case SimpleDynamicTag::BOOLEAN: return ELpxSimpleDynamicTag::Boolean;
|
case SimpleDynamicTag::BOOLEAN: return ELpxSimpleDynamicTag::Boolean;
|
||||||
@@ -110,8 +118,15 @@ FString UlxLuaCallLibrary::LuaCallGetStringResult(UObject *context) {
|
|||||||
FlxStreamBuffer &sb = mode->LuaCallGetResult();
|
FlxStreamBuffer &sb = mode->LuaCallGetResult();
|
||||||
SimpleDynamicTag tag = sb.read_simple_dynamic_tag();
|
SimpleDynamicTag tag = sb.read_simple_dynamic_tag();
|
||||||
if (tag != SimpleDynamicTag::STRING) FatalBlueprintError(TEXT("expected lua to return a string"));
|
if (tag != SimpleDynamicTag::STRING) FatalBlueprintError(TEXT("expected lua to return a string"));
|
||||||
std::string_view s = sb.read_string_view();
|
return sb.read_fstring();
|
||||||
return FString(s.size(), (const UTF8CHAR *)s.data());
|
}
|
||||||
|
|
||||||
|
FName UlxLuaCallLibrary::LuaCallGetNameResult(UObject *context) {
|
||||||
|
AIntegrationGameModeBase *mode = AIntegrationGameModeBase::GetFromContext(context);
|
||||||
|
FlxStreamBuffer &sb = mode->LuaCallGetResult();
|
||||||
|
SimpleDynamicTag tag = sb.read_simple_dynamic_tag();
|
||||||
|
if (tag != SimpleDynamicTag::TOKEN) FatalBlueprintError(TEXT("expected lua to return a name"));
|
||||||
|
return sb.read_fname();
|
||||||
}
|
}
|
||||||
|
|
||||||
double UlxLuaCallLibrary::LuaCallGetFloatResult(UObject *context) {
|
double UlxLuaCallLibrary::LuaCallGetFloatResult(UObject *context) {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ UENUM(BlueprintType)
|
|||||||
enum class ELpxSimpleDynamicTag : uint8 {
|
enum class ELpxSimpleDynamicTag : uint8 {
|
||||||
None,
|
None,
|
||||||
String,
|
String,
|
||||||
|
Name,
|
||||||
Float,
|
Float,
|
||||||
Boolean,
|
Boolean,
|
||||||
Vector
|
Vector
|
||||||
@@ -32,6 +33,9 @@ public:
|
|||||||
UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"), Category = "Luprex|Call Lua Function")
|
UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"), Category = "Luprex|Call Lua Function")
|
||||||
static void LuaCallAddStringParameter(UObject *context, const FString &pstring);
|
static void LuaCallAddStringParameter(UObject *context, const FString &pstring);
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"), Category = "Luprex|Call Lua Function")
|
||||||
|
static void LuaCallAddNameParameter(UObject *context, const FName &pname);
|
||||||
|
|
||||||
UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"), Category = "Luprex|Call Lua Function")
|
UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"), Category = "Luprex|Call Lua Function")
|
||||||
static void LuaCallAddFloatParameter(UObject *context, double pfloat);
|
static void LuaCallAddFloatParameter(UObject *context, double pfloat);
|
||||||
|
|
||||||
@@ -56,6 +60,9 @@ public:
|
|||||||
UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"), Category = "Luprex|Call Lua Function")
|
UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"), Category = "Luprex|Call Lua Function")
|
||||||
static FString LuaCallGetStringResult(UObject *context);
|
static FString LuaCallGetStringResult(UObject *context);
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"), Category = "Luprex|Call Lua Function")
|
||||||
|
static FName LuaCallGetNameResult(UObject *context);
|
||||||
|
|
||||||
UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"), Category = "Luprex|Call Lua Function")
|
UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"), Category = "Luprex|Call Lua Function")
|
||||||
static double LuaCallGetFloatResult(UObject *context);
|
static double LuaCallGetFloatResult(UObject *context);
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,11 @@ public:
|
|||||||
write_string(std::string_view(utf8str.Get(), utf8str.Length()));
|
write_string(std::string_view(utf8str.Get(), utf8str.Length()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void write_fname(const FName &name) {
|
||||||
|
FTCHARToUTF8 utf8str(name.ToString());
|
||||||
|
write_string(std::string_view(utf8str.Get(), utf8str.Length()));
|
||||||
|
}
|
||||||
|
|
||||||
void write_string(const char *s) {
|
void write_string(const char *s) {
|
||||||
write_string(std::string_view(s));
|
write_string(std::string_view(s));
|
||||||
}
|
}
|
||||||
@@ -53,5 +58,15 @@ public:
|
|||||||
double z = read_double();
|
double z = read_double();
|
||||||
return FVector(x, y, z);
|
return FVector(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FString read_fstring() {
|
||||||
|
std::string_view s = read_string_view();
|
||||||
|
return FString(s.size(), (const UTF8CHAR *)s.data());
|
||||||
|
}
|
||||||
|
|
||||||
|
FName read_fname() {
|
||||||
|
std::string_view s = read_string_view();
|
||||||
|
return FName(s.size(), (const UTF8CHAR *)s.data(), FNAME_Add);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,16 @@
|
|||||||
void push_simple_dynamic(lua_State *L, StreamBuffer *sb) {
|
void push_simple_dynamic(lua_State *L, StreamBuffer *sb) {
|
||||||
SimpleDynamicTag type = sb->read_simple_dynamic_tag();
|
SimpleDynamicTag type = sb->read_simple_dynamic_tag();
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
case SimpleDynamicTag::STRING: {
|
||||||
|
std::string_view s = sb->read_string_view();
|
||||||
|
lua_pushlstring(L, s.data(), s.size());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SimpleDynamicTag::TOKEN: {
|
||||||
|
LuaToken token(sb->read_string_view());
|
||||||
|
lua_pushlightuserdata(L, token.voidvalue());
|
||||||
|
break;
|
||||||
|
}
|
||||||
case SimpleDynamicTag::NUMBER: {
|
case SimpleDynamicTag::NUMBER: {
|
||||||
lua_pushnumber(L, sb->read_double());
|
lua_pushnumber(L, sb->read_double());
|
||||||
break;
|
break;
|
||||||
@@ -21,11 +31,6 @@ void push_simple_dynamic(lua_State *L, StreamBuffer *sb) {
|
|||||||
lua_pushboolean(L, sb->read_bool() ? 1:0);
|
lua_pushboolean(L, sb->read_bool() ? 1:0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SimpleDynamicTag::STRING: {
|
|
||||||
std::string_view s = sb->read_string_view();
|
|
||||||
lua_pushlstring(L, s.data(), s.size());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case SimpleDynamicTag::VECTOR: {
|
case SimpleDynamicTag::VECTOR: {
|
||||||
double x = sb->read_double();
|
double x = sb->read_double();
|
||||||
double y = sb->read_double();
|
double y = sb->read_double();
|
||||||
@@ -46,14 +51,18 @@ void push_simple_dynamic(lua_State *L, StreamBuffer *sb) {
|
|||||||
// Given a lua value, try to pack it into the stream buffer as a simple dynamic.
|
// Given a lua value, try to pack it into the stream buffer as a simple dynamic.
|
||||||
bool encode_simple_dynamic(LuaCoreStack &LS, LuaSlot &slot, StreamBuffer *sb) {
|
bool encode_simple_dynamic(LuaCoreStack &LS, LuaSlot &slot, StreamBuffer *sb) {
|
||||||
switch (LS.type(slot)) {
|
switch (LS.type(slot)) {
|
||||||
case LUA_TNUMBER:
|
|
||||||
sb->write_simple_dynamic_tag(SimpleDynamicTag::NUMBER);
|
|
||||||
sb->write_double(LS.cknumber(slot));
|
|
||||||
return true;
|
|
||||||
case LUA_TSTRING:
|
case LUA_TSTRING:
|
||||||
sb->write_simple_dynamic_tag(SimpleDynamicTag::STRING);
|
sb->write_simple_dynamic_tag(SimpleDynamicTag::STRING);
|
||||||
sb->write_string(LS.ckstringview(slot));
|
sb->write_string(LS.ckstringview(slot));
|
||||||
return true;
|
return true;
|
||||||
|
case LUA_TLIGHTUSERDATA:
|
||||||
|
sb->write_simple_dynamic_tag(SimpleDynamicTag::TOKEN);
|
||||||
|
sb->write_string(LS.cktoken(slot).str());
|
||||||
|
return true;
|
||||||
|
case LUA_TNUMBER:
|
||||||
|
sb->write_simple_dynamic_tag(SimpleDynamicTag::NUMBER);
|
||||||
|
sb->write_double(LS.cknumber(slot));
|
||||||
|
return true;
|
||||||
case LUA_TBOOLEAN:
|
case LUA_TBOOLEAN:
|
||||||
sb->write_simple_dynamic_tag(SimpleDynamicTag::BOOLEAN);
|
sb->write_simple_dynamic_tag(SimpleDynamicTag::BOOLEAN);
|
||||||
sb->write_bool(LS.ckboolean(slot));
|
sb->write_bool(LS.ckboolean(slot));
|
||||||
|
|||||||
Reference in New Issue
Block a user