From: Pasi Kallinen Date: Wed, 26 Feb 2020 15:57:47 +0000 (+0200) Subject: Lua: accept different params for gold function X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=816079c8ddfdd6b4e9061c6476101edb95652b99;p=nethack Lua: accept different params for gold function --- diff --git a/src/sp_lev.c b/src/sp_lev.c index 811dd1685..8b5a253d4 100755 --- a/src/sp_lev.c +++ b/src/sp_lev.c @@ -3935,11 +3935,15 @@ lua_State *L; return 0; } +/* gold(500, 3,5); */ +/* gold(500, {5, 6}); */ /* gold({ amount = 500, x = 2, y = 5 });*/ +/* gold(); */ int lspo_gold(L) lua_State *L; { + int argc = lua_gettop(L); schar x, y; long amount; long gcoord; @@ -3947,16 +3951,31 @@ lua_State *L; create_des_coder(); - lcheck_param_table(L); + if (argc == 3) { + amount = luaL_checkinteger(L, 1); + x = gx = luaL_checkinteger(L, 2); + y = gy = luaL_checkinteger(L, 2); + } else if (argc == 2 && lua_type(L, 2) == LUA_TTABLE) { + amount = luaL_checkinteger(L, 1); + get_coord(L, 2, &gx, &gy); + x = gx; + y = gy; + } else if (argc == 0 || (argc == 1 && lua_type(L, 1) == LUA_TTABLE)) { + lcheck_param_table(L); - x = gx = get_table_int_opt(L, "x", -1); - y = gy = get_table_int_opt(L, "y", -1); + amount = get_table_int_opt(L, "amount", -1); + x = gx = get_table_int_opt(L, "x", -1); + y = gy = get_table_int_opt(L, "y", -1); + } else { + nhl_error(L, "Wrong parameters"); + return 0; + } if (x == -1 && y == -1) gcoord = SP_COORD_PACK_RANDOM(0); else gcoord = SP_COORD_PACK(gx, gy); - amount = get_table_int_opt(L, "amount", -1); + get_location_coord(&x, &y, DRY, g.coder->croom, gcoord); if (amount < 0) amount = rnd(200); diff --git a/test/test_des.lua b/test/test_des.lua index 1e8487530..c006cb057 100644 --- a/test/test_des.lua +++ b/test/test_des.lua @@ -211,6 +211,9 @@ end function test_gold() des.gold({ amount = 999, x = 40, y = 07 }); + des.gold(); + des.gold(666, 41,07); + des.gold(123, {42,07}); end function test_trap()