🐳 chore(工具): 更新 lua ecs

develop
xiaojin 5 years ago
parent f02ccab557
commit 30eff9a766

@ -162,6 +162,9 @@ add_component_id_(lua_State *L, int world_index, struct entity_world *w, int cid
}
++pool->n;
pool->id[index] = eid;
if (index > 0 && eid <= pool->id[index-1]) {
luaL_error(L, "Add component %d fail", cid);
}
return index;
}
@ -1119,7 +1122,7 @@ update_iter(lua_State *L, int world_index, int lua_index, struct group_iter *ite
luaL_error(L, "Missing lua table for %d", k->id);
}
lua_insert(L, -2);
lua_rawseti(L, -2, index);
lua_rawseti(L, -2, index + 1);
} else {
void *buffer = entity_add_sibling_(iter->world, mainkey, idx, k->id, NULL, L, world_index);
write_component_object(L, k->field_n, f, buffer);

@ -0,0 +1,39 @@
local ecs = require "ecs"
local w = ecs.world()
w:register {
name = "key",
type = "int",
}
w:register {
name = "temp",
type = "lua",
}
for i = 1, 10 do
w:new { key = i }
end
local function add_temp(i)
for v in w:select "key:in temp?temp" do
if v.key == i then
v.temp = "Temp"
end
end
end
local function print_entity()
for v in w:select "key:in temp:in" do
print(v.key, v.temp)
end
end
add_temp(5)
print_entity()
add_temp(6)
print_entity()
assert(pcall(add_temp, 4) == false)
Loading…
Cancel
Save