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

Function l_obj_new_readobjnam

src/nhlobj.c:349–384  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

347/* local o = obj.new("rock"); */
348/* local o = obj.new({ id = "food ration", class = "%" }); */
349staticfn int
350l_obj_new_readobjnam(lua_State *L)
351{
352 int argc = lua_gettop(L);
353
354 if (argc == 1 && lua_type(L, 1) == LUA_TSTRING) {
355 char buf[BUFSZ];
356 struct obj *otmp;
357
358 Sprintf(buf, "%s", luaL_checkstring(L, 1));
359 lua_pop(L, 1);
360 if ((otmp = readobjnam(buf, NULL)) == &hands_obj)
361 otmp = NULL;
362 (void) l_obj_push(L, otmp);
363 return 1;
364 } else if (argc == 1 && lua_type(L, 1) == LUA_TTABLE) {
365 short id = get_table_objtype(L);
366 xint16 class = get_table_objclass(L);
367 struct obj *otmp;
368
369 if (id >= FIRST_OBJECT) {
370 otmp = mksobj(id, TRUE, FALSE);
371 } else {
372 class = def_char_to_objclass(class);
373 if (class >= MAXOCLASSES)
374 class = RANDOM_CLASS;
375 otmp = mkobj(class, FALSE);
376 }
377 lua_pop(L, 1);
378 (void) l_obj_push(L, otmp);
379 return 1;
380 } else
381 nhl_error(L, "l_obj_new_readobjname: Wrong args");
382 /*NOTREACHED*/
383 return 0;
384}
385
386/* Get the topmost object on the map at x,y */
387/* local o = obj.at(x, y); */

Callers

nothing calls this directly

Calls 8

readobjnamFunction · 0.85
l_obj_pushFunction · 0.85
get_table_objtypeFunction · 0.85
get_table_objclassFunction · 0.85
mksobjFunction · 0.85
def_char_to_objclassFunction · 0.85
mkobjFunction · 0.85
nhl_errorFunction · 0.85

Tested by

no test coverage detected