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()
389 lua_pushnumber(L,j); in mp_encode_lua_table_as_array()
390 lua_gettable(L,-2); in mp_encode_lua_table_as_array()
391 mp_encode_lua_type(L,buf,level+1); in mp_encode_lua_table_as_array()
396 void mp_encode_lua_table_as_map(lua_State *L, mp_buf *buf, int level) { in mp_encode_lua_table_as_map() argument
403 lua_pushnil(L); in mp_encode_lua_table_as_map()
404 while(lua_next(L,-2)) { in mp_encode_lua_table_as_map()
405 lua_pop(L,1); /* remove value, keep key for next iteration. */ in mp_encode_lua_table_as_map()
410 mp_encode_map(L,buf,len); in mp_encode_lua_table_as_map()
411 lua_pushnil(L); in mp_encode_lua_table_as_map()
412 while(lua_next(L,-2)) { in mp_encode_lua_table_as_map()
414 lua_pushvalue(L,-2); /* Stack: ... key value key */ in mp_encode_lua_table_as_map()
415 mp_encode_lua_type(L,buf,level+1); /* encode key */ in mp_encode_lua_table_as_map()
416 mp_encode_lua_type(L,buf,level+1); /* encode val */ in mp_encode_lua_table_as_map()
423 int table_is_an_array(lua_State *L) { in table_is_an_array() argument
434 stacktop = lua_gettop(L); in table_is_an_array()
436 lua_pushnil(L); in table_is_an_array()
437 while(lua_next(L,-2)) { in table_is_an_array()
439 lua_pop(L,1); /* Stack: ... key */ in table_is_an_array()
442 if ((LUA_TNUMBER != lua_type(L,-1)) || (n = lua_tonumber(L, -1)) <= 0 || in table_is_an_array()
445 if (!lua_isinteger(L,-1) || (n = lua_tointeger(L, -1)) <= 0) in table_is_an_array()
448 lua_settop(L, stacktop); in table_is_an_array()
459 lua_settop(L, stacktop); in table_is_an_array()
466 void mp_encode_lua_table(lua_State *L, mp_buf *buf, int level) { in mp_encode_lua_table() argument
467 if (table_is_an_array(L)) in mp_encode_lua_table()
468 mp_encode_lua_table_as_array(L,buf,level); in mp_encode_lua_table()
470 mp_encode_lua_table_as_map(L,buf,level); in mp_encode_lua_table()
473 void mp_encode_lua_null(lua_State *L, mp_buf *buf) { in mp_encode_lua_null() argument
477 mp_buf_append(L,buf,b,1); in mp_encode_lua_null()
480 void mp_encode_lua_type(lua_State *L, mp_buf *buf, int level) { in mp_encode_lua_type() argument
481 int t = lua_type(L,-1); in mp_encode_lua_type()
487 case LUA_TSTRING: mp_encode_lua_string(L,buf); break; in mp_encode_lua_type()
488 case LUA_TBOOLEAN: mp_encode_lua_bool(L,buf); break; in mp_encode_lua_type()
491 mp_encode_lua_number(L,buf); break; in mp_encode_lua_type()
493 if (lua_isinteger(L, -1)) { in mp_encode_lua_type()
494 mp_encode_lua_integer(L, buf); in mp_encode_lua_type()
496 mp_encode_lua_number(L, buf); in mp_encode_lua_type()
500 case LUA_TTABLE: mp_encode_lua_table(L,buf,level); break; in mp_encode_lua_type()
501 default: mp_encode_lua_null(L,buf); break; in mp_encode_lua_type()
503 lua_pop(L,1); in mp_encode_lua_type()
510 int mp_pack(lua_State *L) { in mp_pack() argument
511 int nargs = lua_gettop(L); in mp_pack()
516 return luaL_argerror(L, 0, "MessagePack pack needs input."); in mp_pack()
518 buf = mp_buf_new(L); in mp_pack()
522 lua_pushvalue(L, i); in mp_pack()
524 mp_encode_lua_type(L,buf,0); in mp_pack()
526 lua_pushlstring(L,(char*)buf->b,buf->len); in mp_pack()
534 mp_buf_free(L, buf); in mp_pack()
537 lua_concat(L, nargs); in mp_pack()
543 void mp_decode_to_lua_type(lua_State *L, mp_cur *c);
545 void mp_decode_to_lua_array(lua_State *L, mp_cur *c, size_t len) { in mp_decode_to_lua_array() argument
549 lua_newtable(L); in mp_decode_to_lua_array()
551 lua_pushnumber(L,index++); in mp_decode_to_lua_array()
552 mp_decode_to_lua_type(L,c); in mp_decode_to_lua_array()
554 lua_settable(L,-3); in mp_decode_to_lua_array()
558 void mp_decode_to_lua_hash(lua_State *L, mp_cur *c, size_t len) { in mp_decode_to_lua_hash() argument
560 lua_newtable(L); in mp_decode_to_lua_hash()
562 mp_decode_to_lua_type(L,c); /* key */ in mp_decode_to_lua_hash()
564 mp_decode_to_lua_type(L,c); /* value */ in mp_decode_to_lua_hash()
566 lua_settable(L,-3); in mp_decode_to_lua_hash()
572 void mp_decode_to_lua_type(lua_State *L, mp_cur *c) { in mp_decode_to_lua_type() argument
580 luaL_checkstack(L, 1, in mp_decode_to_lua_type()
587 lua_pushunsigned(L,c->p[1]); in mp_decode_to_lua_type()
592 lua_pushinteger(L,(signed char)c->p[1]); in mp_decode_to_lua_type()
597 lua_pushunsigned(L, in mp_decode_to_lua_type()
604 lua_pushinteger(L,(int16_t) in mp_decode_to_lua_type()
611 lua_pushunsigned(L, in mp_decode_to_lua_type()
620 lua_pushinteger(L, in mp_decode_to_lua_type()
629 lua_pushunsigned(L, in mp_decode_to_lua_type()
643 lua_pushnumber(L, in mp_decode_to_lua_type()
645 lua_pushinteger(L, in mp_decode_to_lua_type()
658 lua_pushnil(L); in mp_decode_to_lua_type()
662 lua_pushboolean(L,1); in mp_decode_to_lua_type()
666 lua_pushboolean(L,0); in mp_decode_to_lua_type()
676 lua_pushnumber(L,f); in mp_decode_to_lua_type()
687 lua_pushnumber(L,d); in mp_decode_to_lua_type()
696 lua_pushlstring(L,(char*)c->p+2,l); in mp_decode_to_lua_type()
705 lua_pushlstring(L,(char*)c->p+3,l); in mp_decode_to_lua_type()
718 lua_pushlstring(L,(char*)c->p,l); in mp_decode_to_lua_type()
727 mp_decode_to_lua_array(L,c,l); in mp_decode_to_lua_type()
738 mp_decode_to_lua_array(L,c,l); in mp_decode_to_lua_type()
746 mp_decode_to_lua_hash(L,c,l); in mp_decode_to_lua_type()
757 mp_decode_to_lua_hash(L,c,l); in mp_decode_to_lua_type()
762 lua_pushunsigned(L,c->p[0]); in mp_decode_to_lua_type()
765 lua_pushinteger(L,(signed char)c->p[0]); in mp_decode_to_lua_type()
770 lua_pushlstring(L,(char*)c->p+1,l); in mp_decode_to_lua_type()
775 mp_decode_to_lua_array(L,c,l); in mp_decode_to_lua_type()
779 mp_decode_to_lua_hash(L,c,l); in mp_decode_to_lua_type()
786 int mp_unpack_full(lua_State *L, int limit, int offset) { in mp_unpack_full() argument
793 s = luaL_checklstring(L,1,&len); /* if no match, exits */ in mp_unpack_full()
796 return luaL_error(L, in mp_unpack_full()
800 return luaL_error(L, in mp_unpack_full()
810 mp_decode_to_lua_type(L,&c); in mp_unpack_full()
813 return luaL_error(L,"Missing bytes in input."); in mp_unpack_full()
815 return luaL_error(L,"Bad data format in input."); in mp_unpack_full()
825 lua_pushinteger(L, c.left == 0 ? -1 : offset); in mp_unpack_full()
832 lua_insert(L, 2); in mp_unpack_full()
839 int mp_unpack(lua_State *L) { in mp_unpack() argument
840 return mp_unpack_full(L, 0, 0); in mp_unpack()
843 int mp_unpack_one(lua_State *L) { in mp_unpack_one() argument
844 int offset = luaL_optinteger(L, 2, 0); in mp_unpack_one()
846 lua_pop(L, lua_gettop(L)-1); in mp_unpack_one()
847 return mp_unpack_full(L, 1, offset); in mp_unpack_one()
850 int mp_unpack_limit(lua_State *L) { in mp_unpack_limit() argument
851 int limit = luaL_checkinteger(L, 2); in mp_unpack_limit()
852 int offset = luaL_optinteger(L, 3, 0); in mp_unpack_limit()
854 lua_pop(L, lua_gettop(L)-1); in mp_unpack_limit()
856 return mp_unpack_full(L, limit, offset); in mp_unpack_limit()
859 int mp_safe(lua_State *L) { in mp_safe() argument
862 argc = lua_gettop(L); in mp_safe()
866 lua_pushvalue(L, lua_upvalueindex(1)); in mp_safe()
867 lua_insert(L, 1); in mp_safe()
869 err = lua_pcall(L, argc, LUA_MULTRET, 0); in mp_safe()
870 total_results = lua_gettop(L); in mp_safe()
875 lua_pushnil(L); in mp_safe()
876 lua_insert(L,-2); in mp_safe()
890 int luaopen_create(lua_State *L) { in luaopen_create() argument
894 lua_newtable(L); in luaopen_create()
897 lua_pushcfunction(L, cmds[i].func); in luaopen_create()
898 lua_setfield(L, -2, cmds[i].name); in luaopen_create()
902 lua_pushliteral(L, LUACMSGPACK_NAME); in luaopen_create()
903 lua_setfield(L, -2, "_NAME"); in luaopen_create()
904 lua_pushliteral(L, LUACMSGPACK_VERSION); in luaopen_create()
905 lua_setfield(L, -2, "_VERSION"); in luaopen_create()
906 lua_pushliteral(L, LUACMSGPACK_COPYRIGHT); in luaopen_create()
907 lua_setfield(L, -2, "_COPYRIGHT"); in luaopen_create()
908 lua_pushliteral(L, LUACMSGPACK_DESCRIPTION); in luaopen_create()
909 lua_setfield(L, -2, "_DESCRIPTION"); in luaopen_create()
913 LUALIB_API int luaopen_cmsgpack(lua_State *L) { in luaopen_cmsgpack() argument
914 luaopen_create(L); in luaopen_cmsgpack()
918 lua_pushvalue(L, -1); in luaopen_cmsgpack()
919 lua_setglobal(L, LUACMSGPACK_NAME); in luaopen_cmsgpack()
925 LUALIB_API int luaopen_cmsgpack_safe(lua_State *L) { in luaopen_cmsgpack_safe() argument
928 luaopen_cmsgpack(L); in luaopen_cmsgpack_safe()
932 lua_getfield(L, -1, cmds[i].name); in luaopen_cmsgpack_safe()
933 lua_pushcclosure(L, mp_safe, 1); in luaopen_cmsgpack_safe()
934 lua_setfield(L, -2, cmds[i].name); in luaopen_cmsgpack_safe()
939 lua_pushvalue(L, -1); in luaopen_cmsgpack_safe()
940 lua_setglobal(L, LUACMSGPACK_SAFE_NAME); in luaopen_cmsgpack_safe()