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

Function l_obj_objects_to_table

src/nhlobj.c:170–238  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

168/* local odata = obj.class(obj.new("rock")); */
169/* local odata = o:class(); */
170staticfn int
171l_obj_objects_to_table(lua_State *L)
172{
173 int argc = lua_gettop(L);
174 int otyp = -1;
175 struct objclass *o;
176
177 if (argc != 1) {
178 nhl_error(L, "l_obj_objects_to_table: Wrong args");
179 /*NOTREACHED*/
180 return 0;
181 }
182
183 if (lua_type(L, 1) == LUA_TNUMBER) {
184 otyp = (int) luaL_checkinteger(L, 1);
185 } else if (lua_type(L, 1) == LUA_TUSERDATA) {
186 struct _lua_obj *lo = l_obj_check(L, 1);
187 if (lo && lo->obj)
188 otyp = lo->obj->otyp;
189 }
190 lua_pop(L, 1);
191
192 if (otyp == -1) {
193 nhl_error(L, "l_obj_objects_to_table: Wrong args");
194 /*NOTREACHED*/
195 return 0;
196 }
197
198 o = &objects[otyp];
199
200 lua_newtable(L);
201
202 if (OBJ_NAME(objects[otyp]))
203 nhl_add_table_entry_str(L, "name", OBJ_NAME(objects[otyp]));
204 if (OBJ_DESCR(objects[otyp]))
205 nhl_add_table_entry_str(L, "descr",
206 OBJ_DESCR(objects[otyp]));
207 if (o->oc_uname)
208 nhl_add_table_entry_str(L, "uname", o->oc_uname);
209
210 nhl_add_table_entry_int(L, "name_known", o->oc_name_known);
211 nhl_add_table_entry_int(L, "merge", o->oc_merge);
212 nhl_add_table_entry_int(L, "uses_known", o->oc_uses_known);
213 nhl_add_table_entry_int(L, "encountered", o->oc_encountered);
214 nhl_add_table_entry_int(L, "magic", o->oc_magic);
215 nhl_add_table_entry_int(L, "charged", o->oc_charged);
216 nhl_add_table_entry_int(L, "unique", o->oc_unique);
217 nhl_add_table_entry_int(L, "nowish", o->oc_nowish);
218 nhl_add_table_entry_int(L, "big", o->oc_big);
219 /* TODO: oc_bimanual, oc_bulky */
220 nhl_add_table_entry_int(L, "tough", o->oc_tough);
221 nhl_add_table_entry_int(L, "dir", o->oc_dir); /* TODO: convert to text */
222 nhl_add_table_entry_str(L, "material", materialnm[o->oc_material]);
223 /* TODO: oc_subtyp, oc_skill, oc_armcat */
224 nhl_add_table_entry_int(L, "oprop", o->oc_oprop);
225 nhl_add_table_entry_char(L, "class",
226 def_oc_syms[(uchar) o->oc_class].sym);
227 nhl_add_table_entry_int(L, "delay", o->oc_delay);

Callers

nothing calls this directly

Calls 5

nhl_errorFunction · 0.85
l_obj_checkFunction · 0.85
nhl_add_table_entry_strFunction · 0.85
nhl_add_table_entry_intFunction · 0.85
nhl_add_table_entry_charFunction · 0.85

Tested by

no test coverage detected