| 153 | } |
| 154 | |
| 155 | void bind_ecs(lua_State* L) |
| 156 | { |
| 157 | lua_getglobal(L, "skr"); |
| 158 | |
| 159 | // bind component |
| 160 | { |
| 161 | auto trampoline = +[](lua_State* L) -> int { |
| 162 | auto name = (const char8_t*)luaL_checkstring(L, 1); |
| 163 | auto type = sugoi::type_registry_t::get().get_type(name); |
| 164 | if (type == sugoi::kInvalidSIndex) |
| 165 | { |
| 166 | lua_pushnil(L); |
| 167 | return 1; |
| 168 | } |
| 169 | lua_pushinteger(L, type); |
| 170 | return 1; |
| 171 | }; |
| 172 | lua_pushcfunction(L, trampoline, "component"); |
| 173 | lua_setfield(L, -2, "component"); |
| 174 | } |
| 175 | |
| 176 | // bind batch |
| 177 | { |
| 178 | } |
| 179 | |
| 180 | // bind allocate entities |
| 181 | { |
| 182 | auto trampoline = +[](lua_State* L) -> int { |
| 183 | sugoi_storage_t* storage = (sugoi_storage_t*)lua_touserdata(L, 1); |
| 184 | luaL_argexpected(L, lua_istable(L, 2), 2, "table"); |
| 185 | auto size = luaL_checkinteger(L, 3); |
| 186 | luaL_argexpected(L, lua_isfunction(L, 4), 4, "function"); |
| 187 | // iterate array |
| 188 | auto count = lua_objlen(L, 2); |
| 189 | sugoi::type_builder_t builder; |
| 190 | builder.reserve((uint32_t)count); |
| 191 | for (auto i = 1; i <= count; ++i) |
| 192 | { |
| 193 | lua_rawgeti(L, 2, i); |
| 194 | auto type = luaL_checkinteger(L, -1); |
| 195 | builder.with((sugoi_type_index_t)type); |
| 196 | lua_pop(L, 1); |
| 197 | } |
| 198 | sugoi_entity_type_t type; |
| 199 | type.type = builder.build(); |
| 200 | auto callback = [&](sugoi_chunk_view_t* view) -> void { |
| 201 | sugoi::fixed_stack_scope_t scope(localStack); |
| 202 | auto luaView = init_chunk_view(storage, view, type.type); |
| 203 | lua_pushvalue(L, 3); |
| 204 | *(lua_chunk_view_t**)lua_newuserdata(L, sizeof(void*)) = &luaView; |
| 205 | luaL_getmetatable(L, "lua_chunk_view_t"); |
| 206 | lua_setmetatable(L, -2); |
| 207 | if (lua_pcall(L, 1, 0, 0) != LUA_OK) |
| 208 | { |
| 209 | lua_getglobal(L, "skr"); |
| 210 | lua_getfield(L, -1, "log_error"); |
| 211 | lua_pushvalue(L, -3); |
| 212 | lua_call(L, 1, 0); |
no test coverage detected