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:
19
src/nhlobj.c
19
src/nhlobj.c
@@ -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*/
|
||||
|
||||
Reference in New Issue
Block a user