Engio invocation successful

This commit is contained in:
2023-10-31 13:31:42 -04:00
parent c0c360a3a7
commit c0416cffe9
2 changed files with 41 additions and 19 deletions

View File

@@ -769,6 +769,41 @@ void World::invoke_choose(int64_t actor_id, int64_t place_id, std::string_view d
assert(stack_is_clear());
}
// Read a SimpleDynamic value from the streambuffer and push
// it onto the lua stack.
void push_simple_dynamic(lua_State *L, StreamBuffer *sb) {
SimpleDynamicTag type = sb->read_simple_dynamic_tag();
switch (type) {
case SimpleDynamicTag::NUMBER: {
lua_pushnumber(L, sb->read_double());
break;
}
case SimpleDynamicTag::BOOLEAN: {
lua_pushboolean(L, sb->read_bool() ? 1:0);
break;
}
case SimpleDynamicTag::STRING: {
std::string_view s = sb->read_string_view();
lua_pushlstring(L, s.data(), s.size());
break;
}
case SimpleDynamicTag::VECTOR: {
double x = sb->read_double();
double y = sb->read_double();
double z = sb->read_double();
lua_newtable(L);
lua_pushnumber(L, x);
lua_rawseti(L, -2, 1);
lua_pushnumber(L, y);
lua_rawseti(L, -2, 2);
lua_pushnumber(L, z);
lua_rawseti(L, -2, 3);
break;
}
default: throw StreamCorruption();
}
}
void World::invoke_engio(int64_t actor_id, int64_t place_id, std::string_view datapack) {
assert(stack_is_clear());
@@ -820,7 +855,7 @@ void World::invoke_engio(int64_t actor_id, int64_t place_id, std::string_view da
if (!LS.isfunction(func)) {
return;
}
// Create a new thread, push func, actor, place.
int nargs = 3;
lua_State *CO = LS.newthread(thread);
@@ -831,23 +866,7 @@ void World::invoke_engio(int64_t actor_id, int64_t place_id, std::string_view da
// Push any additional args from the datapack.
try {
while (!datasb.empty()) {
SimpleDynamicTag type = datasb.read_simple_dynamic_tag();
switch (type) {
case SimpleDynamicTag::NUMBER: {
lua_pushnumber(L, datasb.read_double());
break;
}
case SimpleDynamicTag::BOOLEAN: {
lua_pushboolean(L, datasb.read_bool() ? 1:0);
break;
}
case SimpleDynamicTag::STRING: {
std::string_view s = datasb.read_string_view();
lua_pushlstring(L, s.data(), s.size());
break;
}
default: return;
}
push_simple_dynamic(L, &datasb);
nargs++;
}
} catch (const StreamException &exc) {