Lines Matching refs:L

35     #define lua_pushunsigned(L, n) lua_pushnumber(L, n)  argument
37 #define lua_pushunsigned(L, n) lua_pushinteger(L, n) argument
98 void *mp_realloc(lua_State *L, void *target, size_t osize,size_t nsize) { in mp_realloc() argument
102 local_realloc = lua_getallocf(L, &ud); in mp_realloc()
107 mp_buf *mp_buf_new(lua_State *L) { in mp_buf_new() argument
111 buf = (mp_buf*)mp_realloc(L, NULL, 0, sizeof(*buf)); in mp_buf_new()
118 void mp_buf_append(lua_State *L, mp_buf *buf, const unsigned char *s, size_t len) { in mp_buf_append() argument
122 buf->b = (unsigned char*)mp_realloc(L, buf->b, buf->len + buf->free, newsize); in mp_buf_append()
130 void mp_buf_free(lua_State *L, mp_buf *buf) { in mp_buf_free() argument
131 mp_realloc(L, buf->b, buf->len + buf->free, 0); /* realloc to 0 = free */ in mp_buf_free()
132 mp_realloc(L, buf, sizeof(*buf), 0); in mp_buf_free()
174 void mp_encode_bytes(lua_State *L, mp_buf *buf, const unsigned char *s, size_t len) { in mp_encode_bytes() argument
198 mp_buf_append(L,buf,hdr,hdrlen); in mp_encode_bytes()
199 mp_buf_append(L,buf,s,len); in mp_encode_bytes()
203 void mp_encode_double(lua_State *L, mp_buf *buf, double d) { in mp_encode_double() argument
212 mp_buf_append(L,buf,b,5); in mp_encode_double()
217 mp_buf_append(L,buf,b,9); in mp_encode_double()
221 void mp_encode_int(lua_State *L, mp_buf *buf, int64_t n) { in mp_encode_int() argument
290 mp_buf_append(L,buf,b,enclen); in mp_encode_int()
293 void mp_encode_array(lua_State *L, mp_buf *buf, int64_t n) { in mp_encode_array() argument
313 mp_buf_append(L,buf,b,enclen); in mp_encode_array()
316 void mp_encode_map(lua_State *L, mp_buf *buf, int64_t n) { in mp_encode_map() argument
336 mp_buf_append(L,buf,b,enclen); in mp_encode_map()
341 void mp_encode_lua_string(lua_State *L, mp_buf *buf) { in mp_encode_lua_string() argument
345 s = lua_tolstring(L,-1,&len); in mp_encode_lua_string()
346 mp_encode_bytes(L,buf,(const unsigned char*)s,len); in mp_encode_lua_string()
349 void mp_encode_lua_bool(lua_State *L, mp_buf *buf) { in mp_encode_lua_bool() argument
350 unsigned char b = lua_toboolean(L,-1) ? 0xc3 : 0xc2; in mp_encode_lua_bool()
351 mp_buf_append(L,buf,&b,1); in mp_encode_lua_bool()
355 void mp_encode_lua_integer(lua_State *L, mp_buf *buf) { in mp_encode_lua_integer() argument
357 lua_Number i = lua_tonumber(L,-1); in mp_encode_lua_integer()
359 lua_Integer i = lua_tointeger(L,-1); in mp_encode_lua_integer()
361 mp_encode_int(L, buf, (int64_t)i); in mp_encode_lua_integer()
367 void mp_encode_lua_number(lua_State *L, mp_buf *buf) { in mp_encode_lua_number() argument
368 lua_Number n = lua_tonumber(L,-1); in mp_encode_lua_number()
371 mp_encode_lua_integer(L, buf); in mp_encode_lua_number()
373 mp_encode_double(L,buf,(double)n); in mp_encode_lua_number()
377 void mp_encode_lua_type(lua_State *L, mp_buf *buf, int level);
380 void mp_encode_lua_table_as_array(lua_State *L, mp_buf *buf, int level) { in mp_encode_lua_table_as_array() argument
382 size_t len = lua_objlen(L,-1), j; in mp_encode_lua_table_as_array()
384 size_t len = lua_rawlen(L,-1), j; in mp_encode_lua_table_as_array()
387 mp_encode_array(L,buf,len); in mp_encode_lua_table_as_array()
388 luaL_checkstack(L, 1, "in function mp_encode_lua_table_as_array"); in mp_encode_lua_table_as_array()
390 lua_pushnumber(L,j); in mp_encode_lua_table_as_array()
391 lua_gettable(L,-2); in mp_encode_lua_table_as_array()
392 mp_encode_lua_type(L,buf,level+1); in mp_encode_lua_table_as_array()
397 void mp_encode_lua_table_as_map(lua_State *L, mp_buf *buf, int level) { in mp_encode_lua_table_as_map() argument
404 luaL_checkstack(L, 3, "in function mp_encode_lua_table_as_map"); in mp_encode_lua_table_as_map()
405 lua_pushnil(L); in mp_encode_lua_table_as_map()
406 while(lua_next(L,-2)) { in mp_encode_lua_table_as_map()
407 lua_pop(L,1); /* remove value, keep key for next iteration. */ in mp_encode_lua_table_as_map()
412 mp_encode_map(L,buf,len); in mp_encode_lua_table_as_map()
413 lua_pushnil(L); in mp_encode_lua_table_as_map()
414 while(lua_next(L,-2)) { in mp_encode_lua_table_as_map()
416 lua_pushvalue(L,-2); /* Stack: ... key value key */ in mp_encode_lua_table_as_map()
417 mp_encode_lua_type(L,buf,level+1); /* encode key */ in mp_encode_lua_table_as_map()
418 mp_encode_lua_type(L,buf,level+1); /* encode val */ in mp_encode_lua_table_as_map()
425 int table_is_an_array(lua_State *L) { in table_is_an_array() argument
436 stacktop = lua_gettop(L); in table_is_an_array()
438 lua_pushnil(L); in table_is_an_array()
439 while(lua_next(L,-2)) { in table_is_an_array()
441 lua_pop(L,1); /* Stack: ... key */ in table_is_an_array()
444 if ((LUA_TNUMBER != lua_type(L,-1)) || (n = lua_tonumber(L, -1)) <= 0 || in table_is_an_array()
447 if (!lua_isinteger(L,-1) || (n = lua_tointeger(L, -1)) <= 0) in table_is_an_array()
450 lua_settop(L, stacktop); in table_is_an_array()
461 lua_settop(L, stacktop); in table_is_an_array()
468 void mp_encode_lua_table(lua_State *L, mp_buf *buf, int level) { in mp_encode_lua_table() argument
469 if (table_is_an_array(L)) in mp_encode_lua_table()
470 mp_encode_lua_table_as_array(L,buf,level); in mp_encode_lua_table()
472 mp_encode_lua_table_as_map(L,buf,level); in mp_encode_lua_table()
475 void mp_encode_lua_null(lua_State *L, mp_buf *buf) { in mp_encode_lua_null() argument
479 mp_buf_append(L,buf,b,1); in mp_encode_lua_null()
482 void mp_encode_lua_type(lua_State *L, mp_buf *buf, int level) { in mp_encode_lua_type() argument
483 int t = lua_type(L,-1); in mp_encode_lua_type()
489 case LUA_TSTRING: mp_encode_lua_string(L,buf); break; in mp_encode_lua_type()
490 case LUA_TBOOLEAN: mp_encode_lua_bool(L,buf); break; in mp_encode_lua_type()
493 mp_encode_lua_number(L,buf); break; in mp_encode_lua_type()
495 if (lua_isinteger(L, -1)) { in mp_encode_lua_type()
496 mp_encode_lua_integer(L, buf); in mp_encode_lua_type()
498 mp_encode_lua_number(L, buf); in mp_encode_lua_type()
502 case LUA_TTABLE: mp_encode_lua_table(L,buf,level); break; in mp_encode_lua_type()
503 default: mp_encode_lua_null(L,buf); break; in mp_encode_lua_type()
505 lua_pop(L,1); in mp_encode_lua_type()
512 int mp_pack(lua_State *L) { in mp_pack() argument
513 int nargs = lua_gettop(L); in mp_pack()
518 return luaL_argerror(L, 0, "MessagePack pack needs input."); in mp_pack()
520 if (!lua_checkstack(L, nargs)) in mp_pack()
521 return luaL_argerror(L, 0, "Too many arguments for MessagePack pack."); in mp_pack()
523 buf = mp_buf_new(L); in mp_pack()
527 luaL_checkstack(L, 1, "in function mp_check"); in mp_pack()
528 lua_pushvalue(L, i); in mp_pack()
530 mp_encode_lua_type(L,buf,0); in mp_pack()
532 lua_pushlstring(L,(char*)buf->b,buf->len); in mp_pack()
540 mp_buf_free(L, buf); in mp_pack()
543 lua_concat(L, nargs); in mp_pack()
549 void mp_decode_to_lua_type(lua_State *L, mp_cur *c);
551 void mp_decode_to_lua_array(lua_State *L, mp_cur *c, size_t len) { in mp_decode_to_lua_array() argument
555 lua_newtable(L); in mp_decode_to_lua_array()
556 luaL_checkstack(L, 1, "in function mp_decode_to_lua_array"); in mp_decode_to_lua_array()
558 lua_pushnumber(L,index++); in mp_decode_to_lua_array()
559 mp_decode_to_lua_type(L,c); in mp_decode_to_lua_array()
561 lua_settable(L,-3); in mp_decode_to_lua_array()
565 void mp_decode_to_lua_hash(lua_State *L, mp_cur *c, size_t len) { in mp_decode_to_lua_hash() argument
567 lua_newtable(L); in mp_decode_to_lua_hash()
569 mp_decode_to_lua_type(L,c); /* key */ in mp_decode_to_lua_hash()
571 mp_decode_to_lua_type(L,c); /* value */ in mp_decode_to_lua_hash()
573 lua_settable(L,-3); in mp_decode_to_lua_hash()
579 void mp_decode_to_lua_type(lua_State *L, mp_cur *c) { in mp_decode_to_lua_type() argument
587 luaL_checkstack(L, 1, in mp_decode_to_lua_type()
594 lua_pushunsigned(L,c->p[1]); in mp_decode_to_lua_type()
599 lua_pushinteger(L,(signed char)c->p[1]); in mp_decode_to_lua_type()
604 lua_pushunsigned(L, in mp_decode_to_lua_type()
611 lua_pushinteger(L,(int16_t) in mp_decode_to_lua_type()
618 lua_pushunsigned(L, in mp_decode_to_lua_type()
627 lua_pushinteger(L, in mp_decode_to_lua_type()
636 lua_pushunsigned(L, in mp_decode_to_lua_type()
650 lua_pushnumber(L, in mp_decode_to_lua_type()
652 lua_pushinteger(L, in mp_decode_to_lua_type()
665 lua_pushnil(L); in mp_decode_to_lua_type()
669 lua_pushboolean(L,1); in mp_decode_to_lua_type()
673 lua_pushboolean(L,0); in mp_decode_to_lua_type()
683 lua_pushnumber(L,f); in mp_decode_to_lua_type()
694 lua_pushnumber(L,d); in mp_decode_to_lua_type()
703 lua_pushlstring(L,(char*)c->p+2,l); in mp_decode_to_lua_type()
712 lua_pushlstring(L,(char*)c->p+3,l); in mp_decode_to_lua_type()
725 lua_pushlstring(L,(char*)c->p,l); in mp_decode_to_lua_type()
734 mp_decode_to_lua_array(L,c,l); in mp_decode_to_lua_type()
745 mp_decode_to_lua_array(L,c,l); in mp_decode_to_lua_type()
753 mp_decode_to_lua_hash(L,c,l); in mp_decode_to_lua_type()
764 mp_decode_to_lua_hash(L,c,l); in mp_decode_to_lua_type()
769 lua_pushunsigned(L,c->p[0]); in mp_decode_to_lua_type()
772 lua_pushinteger(L,(signed char)c->p[0]); in mp_decode_to_lua_type()
777 lua_pushlstring(L,(char*)c->p+1,l); in mp_decode_to_lua_type()
782 mp_decode_to_lua_array(L,c,l); in mp_decode_to_lua_type()
786 mp_decode_to_lua_hash(L,c,l); in mp_decode_to_lua_type()
793 int mp_unpack_full(lua_State *L, int limit, int offset) { in mp_unpack_full() argument
800 s = luaL_checklstring(L,1,&len); /* if no match, exits */ in mp_unpack_full()
803 return luaL_error(L, in mp_unpack_full()
807 return luaL_error(L, in mp_unpack_full()
817 mp_decode_to_lua_type(L,&c); in mp_unpack_full()
820 return luaL_error(L,"Missing bytes in input."); in mp_unpack_full()
822 return luaL_error(L,"Bad data format in input."); in mp_unpack_full()
832 luaL_checkstack(L, 1, "in function mp_unpack_full"); in mp_unpack_full()
835 lua_pushinteger(L, c.left == 0 ? -1 : offset); in mp_unpack_full()
842 lua_insert(L, 2); in mp_unpack_full()
849 int mp_unpack(lua_State *L) { in mp_unpack() argument
850 return mp_unpack_full(L, 0, 0); in mp_unpack()
853 int mp_unpack_one(lua_State *L) { in mp_unpack_one() argument
854 int offset = luaL_optinteger(L, 2, 0); in mp_unpack_one()
856 lua_pop(L, lua_gettop(L)-1); in mp_unpack_one()
857 return mp_unpack_full(L, 1, offset); in mp_unpack_one()
860 int mp_unpack_limit(lua_State *L) { in mp_unpack_limit() argument
861 int limit = luaL_checkinteger(L, 2); in mp_unpack_limit()
862 int offset = luaL_optinteger(L, 3, 0); in mp_unpack_limit()
864 lua_pop(L, lua_gettop(L)-1); in mp_unpack_limit()
866 return mp_unpack_full(L, limit, offset); in mp_unpack_limit()
869 int mp_safe(lua_State *L) { in mp_safe() argument
872 argc = lua_gettop(L); in mp_safe()
876 lua_pushvalue(L, lua_upvalueindex(1)); in mp_safe()
877 lua_insert(L, 1); in mp_safe()
879 err = lua_pcall(L, argc, LUA_MULTRET, 0); in mp_safe()
880 total_results = lua_gettop(L); in mp_safe()
885 lua_pushnil(L); in mp_safe()
886 lua_insert(L,-2); in mp_safe()
900 int luaopen_create(lua_State *L) { in luaopen_create() argument
904 lua_newtable(L); in luaopen_create()
907 lua_pushcfunction(L, cmds[i].func); in luaopen_create()
908 lua_setfield(L, -2, cmds[i].name); in luaopen_create()
912 lua_pushliteral(L, LUACMSGPACK_NAME); in luaopen_create()
913 lua_setfield(L, -2, "_NAME"); in luaopen_create()
914 lua_pushliteral(L, LUACMSGPACK_VERSION); in luaopen_create()
915 lua_setfield(L, -2, "_VERSION"); in luaopen_create()
916 lua_pushliteral(L, LUACMSGPACK_COPYRIGHT); in luaopen_create()
917 lua_setfield(L, -2, "_COPYRIGHT"); in luaopen_create()
918 lua_pushliteral(L, LUACMSGPACK_DESCRIPTION); in luaopen_create()
919 lua_setfield(L, -2, "_DESCRIPTION"); in luaopen_create()
923 LUALIB_API int luaopen_cmsgpack(lua_State *L) { in luaopen_cmsgpack() argument
924 luaopen_create(L); in luaopen_cmsgpack()
928 lua_pushvalue(L, -1); in luaopen_cmsgpack()
929 lua_setglobal(L, LUACMSGPACK_NAME); in luaopen_cmsgpack()
935 LUALIB_API int luaopen_cmsgpack_safe(lua_State *L) { in luaopen_cmsgpack_safe() argument
938 luaopen_cmsgpack(L); in luaopen_cmsgpack_safe()
942 lua_getfield(L, -1, cmds[i].name); in luaopen_cmsgpack_safe()
943 lua_pushcclosure(L, mp_safe, 1); in luaopen_cmsgpack_safe()
944 lua_setfield(L, -2, cmds[i].name); in luaopen_cmsgpack_safe()
949 lua_pushvalue(L, -1); in luaopen_cmsgpack_safe()
950 lua_setglobal(L, LUACMSGPACK_SAFE_NAME); in luaopen_cmsgpack_safe()