Lines Matching refs:L
42 #define luaL_register(L,n,f) luaL_newlib(L,f) argument
92 static int getnum (lua_State *L, const char **fmt, int df) { in getnum() argument
99 luaL_error(L, "integral size overflow"); in getnum()
111 static size_t optsize (lua_State *L, char opt, const char **fmt) { in optsize() argument
120 case 'c': return getnum(L, fmt, 1); in optsize()
122 int sz = getnum(L, fmt, sizeof(int)); in optsize()
124 luaL_error(L, "integral size %d is larger than limit of %d", in optsize()
148 static void controloptions (lua_State *L, int opt, const char **fmt, in controloptions() argument
155 int a = getnum(L, fmt, MAXALIGN); in controloptions()
157 luaL_error(L, "alignment %d is not a power of 2", a); in controloptions()
162 const char *msg = lua_pushfstring(L, "invalid format option '%c'", opt); in controloptions()
163 luaL_argerror(L, 1, msg); in controloptions()
169 static void putinteger (lua_State *L, luaL_Buffer *b, int arg, int endian, in putinteger() argument
171 lua_Number n = luaL_checknumber(L, arg); in putinteger()
208 static int b_pack (lua_State *L) { in b_pack() argument
210 const char *fmt = luaL_checkstring(L, 1); in b_pack()
215 lua_pushnil(L); /* mark to separate arguments from string buffer */ in b_pack()
216 luaL_buffinit(L, &b); in b_pack()
219 size_t size = optsize(L, opt, &fmt); in b_pack()
226 putinteger(L, &b, arg++, h.endian, size); in b_pack()
234 float f = (float)luaL_checknumber(L, arg++); in b_pack()
240 double d = luaL_checknumber(L, arg++); in b_pack()
247 const char *s = luaL_checklstring(L, arg++, &l); in b_pack()
249 luaL_argcheck(L, l >= (size_t)size, arg, "string too short"); in b_pack()
257 default: controloptions(L, opt, &fmt, &h); in b_pack()
293 static int b_unpack (lua_State *L) { in b_unpack() argument
295 const char *fmt = luaL_checkstring(L, 1); in b_unpack()
297 const char *data = luaL_checklstring(L, 2, &ld); in b_unpack()
298 size_t pos = luaL_optinteger(L, 3, 1) - 1; in b_unpack()
300 lua_settop(L, 2); in b_unpack()
303 size_t size = optsize(L, opt, &fmt); in b_unpack()
305 luaL_argcheck(L, pos+size <= ld, 2, "data string too short"); in b_unpack()
306 luaL_checkstack(L, 1, "too many results"); in b_unpack()
312 lua_pushnumber(L, res); in b_unpack()
322 lua_pushnumber(L, f); in b_unpack()
329 lua_pushnumber(L, d); in b_unpack()
334 if (!lua_isnumber(L, -1)) in b_unpack()
335 luaL_error(L, "format `c0' needs a previous size"); in b_unpack()
336 size = lua_tonumber(L, -1); in b_unpack()
337 lua_pop(L, 1); in b_unpack()
338 luaL_argcheck(L, pos+size <= ld, 2, "data string too short"); in b_unpack()
340 lua_pushlstring(L, data+pos, size); in b_unpack()
346 luaL_error(L, "unfinished string in data"); in b_unpack()
348 lua_pushlstring(L, data+pos, size - 1); in b_unpack()
351 default: controloptions(L, opt, &fmt, &h); in b_unpack()
355 lua_pushinteger(L, pos + 1); in b_unpack()
356 return lua_gettop(L) - 2; in b_unpack()
360 static int b_size (lua_State *L) { in b_size() argument
362 const char *fmt = luaL_checkstring(L, 1); in b_size()
367 size_t size = optsize(L, opt, &fmt); in b_size()
370 luaL_argerror(L, 1, "option 's' has no fixed size"); in b_size()
372 luaL_argerror(L, 1, "option 'c0' has no fixed size"); in b_size()
374 controloptions(L, opt, &fmt, &h); in b_size()
377 lua_pushinteger(L, pos); in b_size()
393 LUALIB_API int luaopen_struct (lua_State *L);
395 LUALIB_API int luaopen_struct (lua_State *L) { in luaopen_struct() argument
396 luaL_register(L, "struct", thislib); in luaopen_struct()