MCPcopy Index your code
hub / github.com/NetHack/NetHack / l_obj_add_to_container

Function l_obj_add_to_container

src/nhlobj.c:113–137  ·  view source on GitHub ↗

Puts object inside another object. */ local box = obj.new("large chest"); box:addcontent(obj.new("rock")); */

Source from the content-addressed store, hash-verified

111 box:addcontent(obj.new("rock"));
112*/
113staticfn int
114l_obj_add_to_container(lua_State *L)
115{
116 struct _lua_obj *lobox = l_obj_check(L, 1);
117 struct _lua_obj *lo = l_obj_check(L, 2);
118 struct obj *otmp;
119 int refs;
120
121 if (!lobj_is_ok(lo) || !lobj_is_ok(lobox))
122 return 0;
123
124 refs = lo->obj->lua_ref_cnt;
125
126 obj_extract_self(lo->obj);
127 otmp = add_to_container(lobox->obj, lo->obj);
128
129 /* was lo->obj merged? */
130 if (otmp != lo->obj) {
131 lo->obj = otmp;
132 lo->obj->lua_ref_cnt += refs;
133 }
134 lobox->obj->owt = weight(lobox->obj);
135
136 return 0;
137}
138
139/* Put object into player's inventory */
140/* u.giveobj(obj.new("rock")); */

Callers

nothing calls this directly

Calls 4

l_obj_checkFunction · 0.85
obj_extract_selfFunction · 0.85
add_to_containerFunction · 0.85
weightFunction · 0.85

Tested by

no test coverage detected