From f38fe55aa432317357a14b4993c75a784bdc75dc Mon Sep 17 00:00:00 2001 From: Mark Pulford Date: Tue, 26 Apr 2011 10:31:15 +0930 Subject: Move verify_arg_count() into lua_json.c --- lua_json.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'lua_json.c') diff --git a/lua_json.c b/lua_json.c index 1d334ea..3c9803c 100644 --- a/lua_json.c +++ b/lua_json.c @@ -31,11 +31,16 @@ #include #include "lua_json.h" -#include "lua_misc.h" #include "strbuf.h" #include "die.h" + +static void verify_arg_count(lua_State *l, int nargs) +{ + luaL_argcheck(l, lua_gettop(l) <= nargs, nargs + 1, "too many arguments"); +} + /* ===== ENCODING ===== */ static void json_encode_exception(lua_State *l, strbuf_t *json, @@ -264,7 +269,7 @@ int lua_c_json_encode(lua_State *l) char *json; int len; - lua_verify_arg_count(l, 1); + verify_arg_count(l, 1); json = lua_json_encode(l, &len); @@ -666,7 +671,7 @@ int lua_c_json_decode(lua_State *l) { const char *json; - lua_verify_arg_count(l, 1); + verify_arg_count(l, 1); luaL_argcheck(l, lua_islightuserdata(l, 1), 1, "missing lightuserdata"); @@ -682,7 +687,7 @@ static int lua_api_json_decode(lua_State *l) { const char *json; - lua_verify_arg_count(l, 1); + verify_arg_count(l, 1); json = luaL_checkstring(l, 1); lua_json_decode(l, json); -- cgit v1.2.3-55-g6feb