Skip to content

Commit

Permalink
Fix CSM crash (#5779)
Browse files Browse the repository at this point in the history
Caused by dc5bc6c and them made worse by 5ebf8f9
  • Loading branch information
red-001 authored and nerzhul committed May 20, 2017
1 parent 7e18506 commit 772944d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion doc/client_lua_api.md
Expand Up @@ -202,7 +202,7 @@ For helper functions see "Vector helpers".
### pointed_thing
* `{type="nothing"}`
* `{type="node", under=pos, above=pos}`
* `{type="object", ref=ObjectRef}`
* `{type="object", id=ObjectID}`

Flag Specifier Format
---------------------
Expand Down
12 changes: 9 additions & 3 deletions src/script/common/c_content.cpp
Expand Up @@ -1441,7 +1441,7 @@ void read_json_value(lua_State *L, Json::Value &root, int index, u8 recursion)
lua_pop(L, 1); // Pop value
}

void push_pointed_thing(lua_State *L, const PointedThing &pointed)
void push_pointed_thing(lua_State *L, const PointedThing &pointed, bool csm)
{
lua_newtable(L);
if (pointed.type == POINTEDTHING_NODE) {
Expand All @@ -1454,8 +1454,14 @@ void push_pointed_thing(lua_State *L, const PointedThing &pointed)
} else if (pointed.type == POINTEDTHING_OBJECT) {
lua_pushstring(L, "object");
lua_setfield(L, -2, "type");
push_objectRef(L, pointed.object_id);
lua_setfield(L, -2, "ref");

if (csm) {
lua_pushinteger(L, pointed.object_id);
lua_setfield(L, -2, "id");
} else {
push_objectRef(L, pointed.object_id);
lua_setfield(L, -2, "ref");
}
} else {
lua_pushstring(L, "nothing");
lua_setfield(L, -2, "type");
Expand Down
2 changes: 1 addition & 1 deletion src/script/common/c_content.h
Expand Up @@ -164,7 +164,7 @@ bool push_json_value (lua_State *L,
void read_json_value (lua_State *L, Json::Value &root,
int index, u8 recursion = 0);

void push_pointed_thing (lua_State *L, const PointedThing &pointed);
void push_pointed_thing (lua_State *L, const PointedThing &pointed, bool csm = false);

void push_objectRef (lua_State *L, const u16 id);

Expand Down
4 changes: 2 additions & 2 deletions src/script/cpp_api/s_client.cpp
Expand Up @@ -199,7 +199,7 @@ bool ScriptApiClient::on_placenode(const PointedThing &pointed, const ItemDefini
lua_getfield(L, -1, "registered_on_placenode");

// Push data
push_pointed_thing(L, pointed);
push_pointed_thing(L, pointed, true);
push_item_definition(L, item);

// Call functions
Expand All @@ -217,7 +217,7 @@ bool ScriptApiClient::on_item_use(const ItemStack &item, const PointedThing &poi

// Push data
LuaItemStack::create(L, item);
push_pointed_thing(L, pointed);
push_pointed_thing(L, pointed, true);

// Call functions
runCallbacks(2, RUN_CALLBACKS_MODE_OR);
Expand Down

0 comments on commit 772944d

Please sign in to comment.