| 347 | /* local o = obj.new("rock"); */ |
| 348 | /* local o = obj.new({ id = "food ration", class = "%" }); */ |
| 349 | staticfn int |
| 350 | l_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); */ |
nothing calls this directly
no test coverage detected