aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Pulford <mark@kyne.com.au>2011-04-26 10:31:15 +0930
committerMark Pulford <mark@kyne.com.au>2011-04-26 10:31:15 +0930
commitf38fe55aa432317357a14b4993c75a784bdc75dc (patch)
treeef8d798a04a0a44c44abac12e50934d0606e1d68
parent2a12b3fa4b8cdef53288aa2667df0dad2d7f2fc2 (diff)
downloadlua-cjson-f38fe55aa432317357a14b4993c75a784bdc75dc.tar.gz
lua-cjson-f38fe55aa432317357a14b4993c75a784bdc75dc.tar.bz2
lua-cjson-f38fe55aa432317357a14b4993c75a784bdc75dc.zip
Move verify_arg_count() into lua_json.c
-rw-r--r--lua_json.c13
1 files changed, 9 insertions, 4 deletions
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 @@
31#include <lauxlib.h> 31#include <lauxlib.h>
32 32
33#include "lua_json.h" 33#include "lua_json.h"
34#include "lua_misc.h"
35#include "strbuf.h" 34#include "strbuf.h"
36 35
37#include "die.h" 36#include "die.h"
38 37
38
39static void verify_arg_count(lua_State *l, int nargs)
40{
41 luaL_argcheck(l, lua_gettop(l) <= nargs, nargs + 1, "too many arguments");
42}
43
39/* ===== ENCODING ===== */ 44/* ===== ENCODING ===== */
40 45
41static void json_encode_exception(lua_State *l, strbuf_t *json, 46static void json_encode_exception(lua_State *l, strbuf_t *json,
@@ -264,7 +269,7 @@ int lua_c_json_encode(lua_State *l)
264 char *json; 269 char *json;
265 int len; 270 int len;
266 271
267 lua_verify_arg_count(l, 1); 272 verify_arg_count(l, 1);
268 273
269 json = lua_json_encode(l, &len); 274 json = lua_json_encode(l, &len);
270 275
@@ -666,7 +671,7 @@ int lua_c_json_decode(lua_State *l)
666{ 671{
667 const char *json; 672 const char *json;
668 673
669 lua_verify_arg_count(l, 1); 674 verify_arg_count(l, 1);
670 luaL_argcheck(l, lua_islightuserdata(l, 1), 1, 675 luaL_argcheck(l, lua_islightuserdata(l, 1), 1,
671 "missing lightuserdata"); 676 "missing lightuserdata");
672 677
@@ -682,7 +687,7 @@ static int lua_api_json_decode(lua_State *l)
682{ 687{
683 const char *json; 688 const char *json;
684 689
685 lua_verify_arg_count(l, 1); 690 verify_arg_count(l, 1);
686 json = luaL_checkstring(l, 1); 691 json = luaL_checkstring(l, 1);
687 692
688 lua_json_decode(l, json); 693 lua_json_decode(l, json);