fix entities.spawn in coroutines
This commit is contained in:
parent
35a6985d7e
commit
bbe5688a53
@ -1,10 +1,12 @@
|
||||
local util = require("core:tests_util")
|
||||
local util = require "core:tests_util"
|
||||
|
||||
-- Create world and prepare settings
|
||||
util.create_demo_world("core:default")
|
||||
app.set_setting("chunks.load-distance", 3)
|
||||
app.set_setting("chunks.load-speed", 1)
|
||||
|
||||
local base_util = require "base:util"
|
||||
|
||||
-- Create player
|
||||
local pid = player.create("Xerxes")
|
||||
player.set_spawnpoint(pid, 0, 100, 0)
|
||||
@ -22,3 +24,7 @@ assert(block.get(0, 2, 0) == 0)
|
||||
|
||||
-- Wait for the block to fall
|
||||
app.sleep_until(function () return block.get(0, 1, 0) == block.index("base:sand") end, 100)
|
||||
|
||||
local drop = base_util.drop({player.get_pos(pid)}, item.index("base:bazalt_breaker"), 11)
|
||||
assert(drop ~= nil)
|
||||
assert(drop.rigidbody ~= nil)
|
||||
|
||||
@ -63,8 +63,10 @@ static int l_spawn(lua::State* L) {
|
||||
if (lua::gettop(L) > 2) {
|
||||
args = lua::tovalue(L, 3);
|
||||
}
|
||||
level->entities->spawn(def, pos, std::move(args));
|
||||
return 1;
|
||||
entityid_t id = level->entities->spawn(def, pos, std::move(args));
|
||||
lua::get_from(L, "entities", "get", true);
|
||||
lua::pushinteger(L, id);
|
||||
return lua::call_nothrow(L, 1);
|
||||
}
|
||||
|
||||
static int l_despawn(lua::State* L) {
|
||||
|
||||
@ -549,6 +549,7 @@ void scripting::on_entity_spawn(
|
||||
const dv::value& saved
|
||||
) {
|
||||
auto L = lua::get_main_state();
|
||||
lua::stackguard guard(L);
|
||||
lua::requireglobal(L, STDCOMP);
|
||||
if (lua::getfield(L, "new_Entity")) {
|
||||
lua::pushinteger(L, eid);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user