Fix CSM crash (#5779)
authorred-001 <red-001@outlook.ie>
Sat, 20 May 2017 14:45:49 +0000 (15:45 +0100)
committerLoïc Blot <nerzhul@users.noreply.github.com>
Sat, 20 May 2017 14:45:49 +0000 (16:45 +0200)
Caused by dc5bc6c and them made worse by 5ebf8f9

doc/client_lua_api.md
src/script/common/c_content.cpp
src/script/common/c_content.h
src/script/cpp_api/s_client.cpp

index 2c0351a11a3920dee05804abd4b257767094b07d..5b70c2a674c236aa5435eadb111697ee7ef5fc08 100644 (file)
@@ -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
 ---------------------
index 8696ad7cb71610df677cff167c550989392c3d7a..7eb1d094b849b5b00f17bd8d4ea189d4b5722076 100644 (file)
@@ -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) {
@@ -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");
index 219c5eb7cbe105569cf36ab893d75b0130d73894..28d8b1e8c83a350dfc755303c5d54fc3cbee2d3e 100644 (file)
@@ -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);
 
index d5ec52407d93d73aaa7b1b26f6abcd2bcb12b90e..55d309fda427c19f40a92792c19b32e50ac2ceb6 100644 (file)
@@ -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
@@ -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);