Lua tests: generation of each object

Test generation of every object, both via des.object and obj.new.
Expose FIRST_OBJECT and LAST_OBJECT numbers to lua.
Add lua nh.int_to_objname, a function to convert integer value to
object base name and class.
Allow creating new nethack lua object by specifying id and class.
This commit is contained in:
Pasi Kallinen
2026-01-26 17:49:45 +02:00
parent b5ca1a3ed8
commit 11bed1f55b
7 changed files with 122 additions and 16 deletions

View File

@@ -345,12 +345,13 @@ DISABLE_WARNING_UNREACHABLE_CODE
/* create a new object via wishing routine */
/* local o = obj.new("rock"); */
/* local o = obj.new({ id = "food ration", class = "%" }); */
staticfn int
l_obj_new_readobjnam(lua_State *L)
{
int argc = lua_gettop(L);
if (argc == 1) {
if (argc == 1 && lua_type(L, 1) == LUA_TSTRING) {
char buf[BUFSZ];
struct obj *otmp;
@@ -360,6 +361,22 @@ l_obj_new_readobjnam(lua_State *L)
otmp = NULL;
(void) l_obj_push(L, otmp);
return 1;
} else if (argc == 1 && lua_type(L, 1) == LUA_TTABLE) {
short id = get_table_objtype(L);
xint16 class = get_table_objclass(L);
struct obj *otmp;
if (id >= FIRST_OBJECT) {
otmp = mksobj(id, TRUE, FALSE);
} else {
class = def_char_to_objclass(class);
if (class >= MAXOCLASSES)
class = RANDOM_CLASS;
otmp = mkobj(class, FALSE);
}
lua_pop(L, 1);
(void) l_obj_push(L, otmp);
return 1;
} else
nhl_error(L, "l_obj_new_readobjname: Wrong args");
/*NOTREACHED*/