Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
lauxlib.c File Reference
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "lua.h"
#include "lauxlib.h"

Go to the source code of this file.

Data Structures

struct  LoadF
 
struct  LoadS
 

Macros

#define lauxlib_c
 
#define LUA_LIB
 
#define LEVELS1   12 /* size of the first part of the stack */
 
#define LEVELS2   10 /* size of the second part of the stack */
 
#define inspectstat(stat, what)   /* no op */
 
#define buffonstack(B)   ((B)->b != (B)->initb)
 
#define freelist   0
 

Typedefs

typedef struct LoadF LoadF
 
typedef struct LoadS LoadS
 

Functions

static int findfield (lua_State *L, int objidx, int level)
 
static int pushglobalfuncname (lua_State *L, lua_Debug *ar)
 
static void pushfuncname (lua_State *L, lua_Debug *ar)
 
static int countlevels (lua_State *L)
 
LUALIB_API void luaL_traceback (lua_State *L, lua_State *L1, const char *msg, int level)
 
LUALIB_API int luaL_argerror (lua_State *L, int narg, const char *extramsg)
 
static int typeerror (lua_State *L, int narg, const char *tname)
 
static void tag_error (lua_State *L, int narg, int tag)
 
LUALIB_API void luaL_where (lua_State *L, int level)
 
LUALIB_API int luaL_error (lua_State *L, const char *fmt,...)
 
LUALIB_API int luaL_fileresult (lua_State *L, int stat, const char *fname)
 
LUALIB_API int luaL_execresult (lua_State *L, int stat)
 
LUALIB_API int luaL_newmetatable (lua_State *L, const char *tname)
 
LUALIB_API void luaL_setmetatable (lua_State *L, const char *tname)
 
LUALIB_API void * luaL_testudata (lua_State *L, int ud, const char *tname)
 
LUALIB_API void * luaL_checkudata (lua_State *L, int ud, const char *tname)
 
LUALIB_API int luaL_checkoption (lua_State *L, int narg, const char *def, const char *const lst[])
 
LUALIB_API void luaL_checkstack (lua_State *L, int space, const char *msg)
 
LUALIB_API void luaL_checktype (lua_State *L, int narg, int t)
 
LUALIB_API void luaL_checkany (lua_State *L, int narg)
 
LUALIB_API const char * luaL_checklstring (lua_State *L, int narg, size_t *len)
 
LUALIB_API const char * luaL_optlstring (lua_State *L, int narg, const char *def, size_t *len)
 
LUALIB_API lua_Number luaL_checknumber (lua_State *L, int narg)
 
LUALIB_API lua_Number luaL_optnumber (lua_State *L, int narg, lua_Number def)
 
LUALIB_API lua_Integer luaL_checkinteger (lua_State *L, int narg)
 
LUALIB_API lua_Unsigned luaL_checkunsigned (lua_State *L, int narg)
 
LUALIB_API lua_Integer luaL_optinteger (lua_State *L, int narg, lua_Integer def)
 
LUALIB_API lua_Unsigned luaL_optunsigned (lua_State *L, int narg, lua_Unsigned def)
 
LUALIB_API char * luaL_prepbuffsize (luaL_Buffer *B, size_t sz)
 
LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l)
 
LUALIB_API void luaL_addstring (luaL_Buffer *B, const char *s)
 
LUALIB_API void luaL_pushresult (luaL_Buffer *B)
 
LUALIB_API void luaL_pushresultsize (luaL_Buffer *B, size_t sz)
 
LUALIB_API void luaL_addvalue (luaL_Buffer *B)
 
LUALIB_API void luaL_buffinit (lua_State *L, luaL_Buffer *B)
 
LUALIB_API char * luaL_buffinitsize (lua_State *L, luaL_Buffer *B, size_t sz)
 
LUALIB_API int luaL_ref (lua_State *L, int t)
 
LUALIB_API void luaL_unref (lua_State *L, int t, int ref)
 
static const char * getF (lua_State *L, void *ud, size_t *size)
 
static int errfile (lua_State *L, const char *what, int fnameindex)
 
static int skipBOM (LoadF *lf)
 
static int skipcomment (LoadF *lf, int *cp)
 
LUALIB_API int luaL_loadfilex (lua_State *L, const char *filename, const char *mode)
 
static const char * getS (lua_State *L, void *ud, size_t *size)
 
LUALIB_API int luaL_loadbufferx (lua_State *L, const char *buff, size_t size, const char *name, const char *mode)
 
LUALIB_API int luaL_loadstring (lua_State *L, const char *s)
 
LUALIB_API int luaL_getmetafield (lua_State *L, int obj, const char *event)
 
LUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *event)
 
LUALIB_API int luaL_len (lua_State *L, int idx)
 
LUALIB_API const char * luaL_tolstring (lua_State *L, int idx, size_t *len)
 
LUALIB_API void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup)
 
LUALIB_API int luaL_getsubtable (lua_State *L, int idx, const char *fname)
 
LUALIB_API void luaL_requiref (lua_State *L, const char *modname, lua_CFunction openf, int glb)
 
LUALIB_API const char * luaL_gsub (lua_State *L, const char *s, const char *p, const char *r)
 
static void * l_alloc (void *ud, void *ptr, size_t osize, size_t nsize)
 
static int panic (lua_State *L)
 
LUALIB_API lua_StateluaL_newstate (void)
 
LUALIB_API void luaL_checkversion_ (lua_State *L, lua_Number ver)
 

Macro Definition Documentation

◆ buffonstack

#define buffonstack ( B)    ((B)->b != (B)->initb)

Definition at line 431 of file lua-5.2.4/src/lauxlib.c.

Referenced by luaL_addvalue(), luaL_prepbuffsize(), and luaL_pushresult().

◆ freelist

#define freelist   0

Definition at line 519 of file lua-5.2.4/src/lauxlib.c.

Referenced by luaL_ref(), and luaL_unref().

◆ inspectstat

#define inspectstat ( stat,
what )   /* no op */

Definition at line 240 of file lua-5.2.4/src/lauxlib.c.

Referenced by luaL_execresult().

◆ lauxlib_c

#define lauxlib_c

Definition at line 19 of file lua-5.2.4/src/lauxlib.c.

◆ LEVELS1

#define LEVELS1   12 /* size of the first part of the stack */

Definition at line 34 of file lua-5.2.4/src/lauxlib.c.

Referenced by luaL_traceback().

◆ LEVELS2

#define LEVELS2   10 /* size of the second part of the stack */

Definition at line 35 of file lua-5.2.4/src/lauxlib.c.

Referenced by luaL_traceback().

◆ LUA_LIB

#define LUA_LIB

Definition at line 20 of file lua-5.2.4/src/lauxlib.c.

Typedef Documentation

◆ LoadF

typedef struct LoadF LoadF

◆ LoadS

typedef struct LoadS LoadS

Function Documentation

◆ countlevels()

static int countlevels ( lua_State * L)
static

Definition at line 101 of file lua-5.2.4/src/lauxlib.c.

101 {
102 lua_Debug ar;
103 int li = 1, le = 1;
104 /* find an upper bound */
105 while (lua_getstack(L, le, &ar)) { li = le; le *= 2; }
106 /* do a binary search */
107 while (li < le) {
108 int m = (li + le)/2;
109 if (lua_getstack(L, m, &ar)) li = m + 1;
110 else le = m;
111 }
112 return le - 1;
113}
LUA_API int lua_getstack(lua_State *L, int level, lua_Debug *ar)

References lua_getstack().

Referenced by luaL_traceback().

◆ errfile()

static int errfile ( lua_State * L,
const char * what,
int fnameindex )
static

Definition at line 587 of file lua-5.2.4/src/lauxlib.c.

587 {
588 const char *serr = strerror(errno);
589 const char *filename = lua_tostring(L, fnameindex) + 1;
590 lua_pushfstring(L, "cannot %s %s: %s", what, filename, serr);
591 lua_remove(L, fnameindex);
592 return LUA_ERRFILE;
593}
LUA_API const char * lua_pushfstring(lua_State *L, const char *fmt,...)
#define LUA_ERRFILE
#define lua_tostring(L, i)
#define lua_remove(L, idx)

References LUA_ERRFILE, lua_pushfstring(), lua_remove, and lua_tostring.

Referenced by luaL_loadfilex().

◆ findfield()

static int findfield ( lua_State * L,
int objidx,
int level )
static

Definition at line 43 of file lua-5.2.4/src/lauxlib.c.

43 {
44 if (level == 0 || !lua_istable(L, -1))
45 return 0; /* not found */
46 lua_pushnil(L); /* start 'next' loop */
47 while (lua_next(L, -2)) { /* for each pair in table */
48 if (lua_type(L, -2) == LUA_TSTRING) { /* ignore non-string keys */
49 if (lua_rawequal(L, objidx, -1)) { /* found object? */
50 lua_pop(L, 1); /* remove value (but keep name) */
51 return 1;
52 }
53 else if (findfield(L, objidx, level - 1)) { /* try recursively */
54 lua_remove(L, -2); /* remove table (but keep name) */
55 lua_pushliteral(L, ".");
56 lua_insert(L, -2); /* place '.' between the two names */
57 lua_concat(L, 3);
58 return 1;
59 }
60 }
61 lua_pop(L, 1); /* remove value */
62 }
63 return 0; /* not found */
64}
LUA_API void lua_pushnil(lua_State *L)
LUA_API void lua_concat(lua_State *L, int n)
LUA_API int lua_type(lua_State *L, int idx)
LUA_API int lua_next(lua_State *L, int idx)
LUA_API int lua_rawequal(lua_State *L, int index1, int index2)
#define lua_istable(L, n)
#define lua_pushliteral(L, s)
#define LUA_TSTRING
#define lua_pop(L, n)
static int findfield(lua_State *L, int objidx, int level)
#define lua_insert(L, idx)

References findfield(), lua_concat(), lua_insert, lua_istable, lua_next(), lua_pop, lua_pushliteral, lua_pushnil(), lua_rawequal(), lua_remove, LUA_TSTRING, and lua_type().

Referenced by findfield(), and pushglobalfuncname().

◆ getF()

static const char * getF ( lua_State * L,
void * ud,
size_t * size )
static

Definition at line 569 of file lua-5.2.4/src/lauxlib.c.

569 {
570 LoadF *lf = (LoadF *)ud;
571 (void)L; /* not used */
572 if (lf->n > 0) { /* are there pre-read characters to be read? */
573 *size = lf->n; /* return them (chars already in buffer) */
574 lf->n = 0; /* no more pre-read characters */
575 }
576 else { /* read a block from file */
577 /* 'fread' can return > 0 *and* set the EOF flag. If next call to
578 'getF' called 'fread', it might still wait for user input.
579 The next check avoids this problem. */
580 if (feof(lf->f)) return NULL;
581 *size = fread(lf->buff, 1, sizeof(lf->buff), lf->f); /* read block */
582 }
583 return lf->buff;
584}
#define NULL
Definition gmacros.h:924
size_t fread(void *, size_t, size_t, FILE *)
char buff[LUAL_BUFFERSIZE]

References LoadF::buff, LoadF::f, fread(), LoadF::n, and NULL.

Referenced by luaL_loadfilex().

◆ getS()

static const char * getS ( lua_State * L,
void * ud,
size_t * size )
static

Definition at line 672 of file lua-5.2.4/src/lauxlib.c.

672 {
673 LoadS *ls = (LoadS *)ud;
674 (void)L; /* not used */
675 if (ls->size == 0) return NULL;
676 *size = ls->size;
677 ls->size = 0;
678 return ls->s;
679}
const char * s

References NULL, LoadS::s, and LoadS::size.

Referenced by luaL_loadbufferx().

◆ l_alloc()

static void * l_alloc ( void * ud,
void * ptr,
size_t osize,
size_t nsize )
static

Definition at line 919 of file lua-5.2.4/src/lauxlib.c.

919 {
920 (void)ud; (void)osize; /* not used */
921 if (nsize == 0) {
922 free(ptr);
923 return NULL;
924 }
925 else
926 return realloc(ptr, nsize);
927}
#define realloc
Definition civetweb.c:1541
#define free
Definition civetweb.c:1542

References free, NULL, and realloc.

Referenced by luaL_newstate().

◆ luaL_addlstring()

LUALIB_API void luaL_addlstring ( luaL_Buffer * B,
const char * s,
size_t l )

Definition at line 459 of file lua-5.2.4/src/lauxlib.c.

459 {
460 char *b = luaL_prepbuffsize(B, l);
461 memcpy(b, s, l * sizeof(char));
462 luaL_addsize(B, l);
463}
#define luaL_addsize(B, n)
LUALIB_API char * luaL_prepbuffsize(luaL_Buffer *B, size_t sz)
CURL_EXTERN CURLMcode curl_socket_t s
Definition multi.h:318

References luaL_addsize, luaL_prepbuffsize(), and s.

Referenced by luaL_addstring(), luaL_addvalue(), and luaL_gsub().

◆ luaL_addstring()

LUALIB_API void luaL_addstring ( luaL_Buffer * B,
const char * s )

Definition at line 466 of file lua-5.2.4/src/lauxlib.c.

466 {
467 luaL_addlstring(B, s, strlen(s));
468}
LUALIB_API void luaL_addlstring(luaL_Buffer *B, const char *s, size_t l)

References luaL_addlstring(), and s.

Referenced by luaL_gsub().

◆ luaL_addvalue()

LUALIB_API void luaL_addvalue ( luaL_Buffer * B)

Definition at line 485 of file lua-5.2.4/src/lauxlib.c.

485 {
486 lua_State *L = B->L;
487 size_t l;
488 const char *s = lua_tolstring(L, -1, &l);
489 if (buffonstack(B))
490 lua_insert(L, -2); /* put value below buffer */
491 luaL_addlstring(B, s, l);
492 lua_remove(L, (buffonstack(B)) ? -2 : -1); /* remove value */
493}
LUA_API const char * lua_tolstring(lua_State *L, int idx, size_t *len)
#define buffonstack(B)

References buffonstack, luaL_Buffer::L, lua_insert, lua_remove, lua_tolstring(), luaL_addlstring(), and s.

◆ luaL_argerror()

LUALIB_API int luaL_argerror ( lua_State * L,
int narg,
const char * extramsg )

Definition at line 153 of file lua-5.2.4/src/lauxlib.c.

153 {
154 lua_Debug ar;
155 if (!lua_getstack(L, 0, &ar)) /* no stack frame? */
156 return luaL_error(L, "bad argument #%d (%s)", narg, extramsg);
157 lua_getinfo(L, "n", &ar);
158 if (strcmp(ar.namewhat, "method") == 0) {
159 narg--; /* do not count `self' */
160 if (narg == 0) /* error is in the self argument itself? */
161 return luaL_error(L, "calling " LUA_QS " on bad self (%s)",
162 ar.name, extramsg);
163 }
164 if (ar.name == NULL)
165 ar.name = (pushglobalfuncname(L, &ar)) ? lua_tostring(L, -1) : "?";
166 return luaL_error(L, "bad argument #%d to " LUA_QS " (%s)",
167 narg, ar.name, extramsg);
168}
LUA_API int lua_getinfo(lua_State *L, const char *what, lua_Debug *ar)
#define LUA_QS
static int pushglobalfuncname(lua_State *L, lua_Debug *ar)
LUALIB_API int luaL_error(lua_State *L, const char *fmt,...)
const char * name
const char * namewhat

References lua_getinfo(), lua_getstack(), LUA_QS, lua_tostring, luaL_error(), lua_Debug::name, lua_Debug::namewhat, NULL, and pushglobalfuncname().

Referenced by luaL_checkany(), luaL_checkoption(), and typeerror().

◆ luaL_buffinit()

LUALIB_API void luaL_buffinit ( lua_State * L,
luaL_Buffer * B )

Definition at line 496 of file lua-5.2.4/src/lauxlib.c.

496 {
497 B->L = L;
498 B->b = B->initb;
499 B->n = 0;
501}
#define LUAL_BUFFERSIZE
char initb[LUAL_BUFFERSIZE]

References luaL_Buffer::b, luaL_Buffer::initb, luaL_Buffer::L, LUAL_BUFFERSIZE, luaL_Buffer::n, and luaL_Buffer::size.

Referenced by luaL_buffinitsize(), and luaL_gsub().

◆ luaL_buffinitsize()

LUALIB_API char * luaL_buffinitsize ( lua_State * L,
luaL_Buffer * B,
size_t sz )

Definition at line 504 of file lua-5.2.4/src/lauxlib.c.

504 {
505 luaL_buffinit(L, B);
506 return luaL_prepbuffsize(B, sz);
507}
LUALIB_API void luaL_buffinit(lua_State *L, luaL_Buffer *B)

References luaL_buffinit(), and luaL_prepbuffsize().

Referenced by str_char(), str_char(), str_char(), str_lower(), str_lower(), str_lower(), str_rep(), str_rep(), str_rep(), str_reverse(), str_reverse(), str_reverse(), str_upper(), str_upper(), and str_upper().

◆ luaL_callmeta()

LUALIB_API int luaL_callmeta ( lua_State * L,
int obj,
const char * event )

Definition at line 715 of file lua-5.2.4/src/lauxlib.c.

715 {
716 obj = lua_absindex(L, obj);
717 if (!luaL_getmetafield(L, obj, event)) /* no metafield? */
718 return 0;
719 lua_pushvalue(L, obj);
720 lua_call(L, 1, 1);
721 return 1;
722}
LUA_API void lua_pushvalue(lua_State *L, int idx)
LUA_API int lua_absindex(lua_State *L, int idx)
LUALIB_API int luaL_getmetafield(lua_State *L, int obj, const char *event)
#define lua_call(L, n, r)

References lua_absindex(), lua_call, lua_pushvalue(), and luaL_getmetafield().

Referenced by luaL_tolstring().

◆ luaL_checkany()

LUALIB_API void luaL_checkany ( lua_State * L,
int narg )

Definition at line 351 of file lua-5.2.4/src/lauxlib.c.

351 {
352 if (lua_type(L, narg) == LUA_TNONE)
353 luaL_argerror(L, narg, "value expected");
354}
#define LUA_TNONE
LUALIB_API int luaL_argerror(lua_State *L, int narg, const char *extramsg)

References LUA_TNONE, lua_type(), and luaL_argerror().

◆ luaL_checkinteger()

LUALIB_API lua_Integer luaL_checkinteger ( lua_State * L,
int narg )

Definition at line 389 of file lua-5.2.4/src/lauxlib.c.

389 {
390 int isnum;
391 lua_Integer d = lua_tointegerx(L, narg, &isnum);
392 if (!isnum)
393 tag_error(L, narg, LUA_TNUMBER);
394 return d;
395}
LUA_INTEGER lua_Integer
#define LUA_TNUMBER
LUA_API lua_Integer lua_tointegerx(lua_State *L, int idx, int *isnum)
static void tag_error(lua_State *L, int narg, int tag)

References LUA_TNUMBER, lua_tointegerx(), and tag_error().

Referenced by luaL_optinteger().

◆ luaL_checklstring()

LUALIB_API const char * luaL_checklstring ( lua_State * L,
int narg,
size_t * len )

Definition at line 357 of file lua-5.2.4/src/lauxlib.c.

357 {
358 const char *s = lua_tolstring(L, narg, len);
359 if (!s) tag_error(L, narg, LUA_TSTRING);
360 return s;
361}

References lua_tolstring(), LUA_TSTRING, s, and tag_error().

Referenced by luaL_optlstring().

◆ luaL_checknumber()

LUALIB_API lua_Number luaL_checknumber ( lua_State * L,
int narg )

Definition at line 375 of file lua-5.2.4/src/lauxlib.c.

375 {
376 int isnum;
377 lua_Number d = lua_tonumberx(L, narg, &isnum);
378 if (!isnum)
379 tag_error(L, narg, LUA_TNUMBER);
380 return d;
381}
LUA_NUMBER lua_Number
LUA_API lua_Number lua_tonumberx(lua_State *L, int idx, int *isnum)

References LUA_TNUMBER, lua_tonumberx(), and tag_error().

Referenced by luaL_optnumber().

◆ luaL_checkoption()

LUALIB_API int luaL_checkoption ( lua_State * L,
int narg,
const char * def,
const char *const lst[] )

Definition at line 320 of file lua-5.2.4/src/lauxlib.c.

321 {
322 const char *name = (def) ? luaL_optstring(L, narg, def) :
323 luaL_checkstring(L, narg);
324 int i;
325 for (i=0; lst[i]; i++)
326 if (strcmp(lst[i], name) == 0)
327 return i;
328 return luaL_argerror(L, narg,
329 lua_pushfstring(L, "invalid option " LUA_QS, name));
330}
const char * name
Definition lsqlite3.c:2154
#define luaL_optstring(L, n, d)
#define luaL_checkstring(L, n)

References lua_pushfstring(), LUA_QS, luaL_argerror(), luaL_checkstring, luaL_optstring, and name.

◆ luaL_checkstack()

LUALIB_API void luaL_checkstack ( lua_State * L,
int space,
const char * msg )

Definition at line 333 of file lua-5.2.4/src/lauxlib.c.

333 {
334 /* keep some extra space to run error routines, if needed */
335 const int extra = LUA_MINSTACK;
336 if (!lua_checkstack(L, space + extra)) {
337 if (msg)
338 luaL_error(L, "stack overflow (%s)", msg);
339 else
340 luaL_error(L, "stack overflow");
341 }
342}
LUA_API int lua_checkstack(lua_State *L, int size)
#define LUA_MINSTACK

References lua_checkstack(), LUA_MINSTACK, and luaL_error().

Referenced by luaL_setfuncs().

◆ luaL_checktype()

LUALIB_API void luaL_checktype ( lua_State * L,
int narg,
int t )

Definition at line 345 of file lua-5.2.4/src/lauxlib.c.

345 {
346 if (lua_type(L, narg) != t)
347 tag_error(L, narg, t);
348}

References lua_type(), and tag_error().

◆ luaL_checkudata()

LUALIB_API void * luaL_checkudata ( lua_State * L,
int ud,
const char * tname )

Definition at line 305 of file lua-5.2.4/src/lauxlib.c.

305 {
306 void *p = luaL_testudata(L, ud, tname);
307 if (p == NULL) typeerror(L, ud, tname);
308 return p;
309}
LUALIB_API void * luaL_testudata(lua_State *L, int ud, const char *tname)
static int typeerror(lua_State *L, int narg, const char *tname)

References luaL_testudata(), NULL, and typeerror().

◆ luaL_checkunsigned()

LUALIB_API lua_Unsigned luaL_checkunsigned ( lua_State * L,
int narg )

Definition at line 398 of file lua-5.2.4/src/lauxlib.c.

398 {
399 int isnum;
400 lua_Unsigned d = lua_tounsignedx(L, narg, &isnum);
401 if (!isnum)
402 tag_error(L, narg, LUA_TNUMBER);
403 return d;
404}
LUA_API lua_Unsigned lua_tounsignedx(lua_State *L, int idx, int *isnum)
LUA_UNSIGNED lua_Unsigned

References LUA_TNUMBER, lua_tounsignedx(), and tag_error().

Referenced by andaux(), b_arshift(), b_extract(), b_lshift(), b_or(), b_replace(), b_rot(), b_rshift(), b_xor(), luaL_optunsigned(), and math_randomseed().

◆ luaL_checkversion_()

LUALIB_API void luaL_checkversion_ ( lua_State * L,
lua_Number ver )

Definition at line 944 of file lua-5.2.4/src/lauxlib.c.

944 {
945 const lua_Number *v = lua_version(L);
946 if (v != lua_version(NULL))
947 luaL_error(L, "multiple Lua VMs detected");
948 else if (*v != ver)
949 luaL_error(L, "version mismatch: app. needs %f, Lua core provides %f",
950 ver, *v);
951 /* check conversions number -> integer types */
952 lua_pushnumber(L, -(lua_Number)0x1234);
953 if (lua_tointeger(L, -1) != -0x1234 ||
954 lua_tounsigned(L, -1) != (lua_Unsigned)-0x1234)
955 luaL_error(L, "bad conversion number->int;"
956 " must recompile Lua with proper settings");
957 lua_pop(L, 1);
958}
LUA_API void lua_pushnumber(lua_State *L, lua_Number n)
LUA_API const lua_Number * lua_version(lua_State *L)
#define lua_tointeger(L, i)
#define lua_tounsigned(L, i)

References lua_pop, lua_pushnumber(), lua_tointeger, lua_tounsigned, lua_version(), luaL_error(), and NULL.

◆ luaL_error()

LUALIB_API int luaL_error ( lua_State * L,
const char * fmt,
... )

Definition at line 196 of file lua-5.2.4/src/lauxlib.c.

196 {
197 va_list argp;
198 va_start(argp, fmt);
199 luaL_where(L, 1);
200 lua_pushvfstring(L, fmt, argp);
201 va_end(argp);
202 lua_concat(L, 2);
203 return lua_error(L);
204}
LUA_API int lua_error(lua_State *L)
LUA_API const char * lua_pushvfstring(lua_State *L, const char *fmt, va_list argp)
LUALIB_API void luaL_where(lua_State *L, int level)

References lua_concat(), lua_error(), lua_pushvfstring(), and luaL_where().

Referenced by luaL_argerror(), luaL_checkstack(), luaL_checkversion_(), luaL_len(), and luaL_prepbuffsize().

◆ luaL_execresult()

LUALIB_API int luaL_execresult ( lua_State * L,
int stat )

Definition at line 247 of file lua-5.2.4/src/lauxlib.c.

247 {
248 const char *what = "exit"; /* type of termination */
249 if (stat == -1) /* error? */
250 return luaL_fileresult(L, 0, NULL);
251 else {
252 inspectstat(stat, what); /* interpret result */
253 if (*what == 'e' && stat == 0) /* successful termination? */
254 lua_pushboolean(L, 1);
255 else
256 lua_pushnil(L);
257 lua_pushstring(L, what);
258 lua_pushinteger(L, stat);
259 return 3; /* return true/nil,what,code */
260 }
261}
LUA_API void lua_pushstring(lua_State *L, const char *s)
LUA_API void lua_pushboolean(lua_State *L, int b)
LUA_API void lua_pushinteger(lua_State *L, lua_Integer n)
LUALIB_API int luaL_fileresult(lua_State *L, int stat, const char *fname)
#define inspectstat(stat, what)

References inspectstat, lua_pushboolean(), lua_pushinteger(), lua_pushnil(), lua_pushstring(), luaL_fileresult(), and NULL.

Referenced by io_pclose(), io_pclose(), io_pclose(), os_execute(), os_execute(), and os_execute().

◆ luaL_fileresult()

LUALIB_API int luaL_fileresult ( lua_State * L,
int stat,
const char * fname )

Definition at line 207 of file lua-5.2.4/src/lauxlib.c.

207 {
208 int en = errno; /* calls to Lua API may change this value */
209 if (stat) {
210 lua_pushboolean(L, 1);
211 return 1;
212 }
213 else {
214 lua_pushnil(L);
215 if (fname)
216 lua_pushfstring(L, "%s: %s", fname, strerror(en));
217 else
218 lua_pushstring(L, strerror(en));
219 lua_pushinteger(L, en);
220 return 3;
221 }
222}

References lua_pushboolean(), lua_pushfstring(), lua_pushinteger(), lua_pushnil(), and lua_pushstring().

Referenced by f_flush(), f_flush(), f_flush(), f_seek(), f_seek(), f_seek(), f_setvbuf(), f_setvbuf(), f_setvbuf(), g_read(), g_read(), g_read(), g_write(), g_write(), g_write(), io_fclose(), io_fclose(), io_fclose(), io_flush(), io_flush(), io_flush(), io_open(), io_open(), io_open(), io_popen(), io_popen(), io_popen(), io_tmpfile(), io_tmpfile(), io_tmpfile(), luaL_execresult(), os_remove(), os_remove(), os_remove(), os_rename(), os_rename(), and os_rename().

◆ luaL_getmetafield()

LUALIB_API int luaL_getmetafield ( lua_State * L,
int obj,
const char * event )

Definition at line 699 of file lua-5.2.4/src/lauxlib.c.

699 {
700 if (!lua_getmetatable(L, obj)) /* no metatable? */
701 return 0;
702 lua_pushstring(L, event);
703 lua_rawget(L, -2);
704 if (lua_isnil(L, -1)) {
705 lua_pop(L, 2); /* remove metatable and metafield */
706 return 0;
707 }
708 else {
709 lua_remove(L, -2); /* remove only metatable */
710 return 1;
711 }
712}
LUA_API void lua_rawget(lua_State *L, int idx)
LUA_API int lua_getmetatable(lua_State *L, int objindex)
#define lua_isnil(L, n)

References lua_getmetatable(), lua_isnil, lua_pop, lua_pushstring(), lua_rawget(), and lua_remove.

Referenced by luaL_callmeta().

◆ luaL_getsubtable()

LUALIB_API int luaL_getsubtable ( lua_State * L,
int idx,
const char * fname )

Definition at line 866 of file lua-5.2.4/src/lauxlib.c.

866 {
867 lua_getfield(L, idx, fname);
868 if (lua_istable(L, -1)) return 1; /* table already there */
869 else {
870 lua_pop(L, 1); /* remove previous result */
871 idx = lua_absindex(L, idx);
872 lua_newtable(L);
873 lua_pushvalue(L, -1); /* copy to be left at top */
874 lua_setfield(L, idx, fname); /* assign new table to field */
875 return 0; /* false, because did not find table there */
876 }
877}
LUA_API void lua_setfield(lua_State *L, int idx, const char *k)
LUA_API void lua_getfield(lua_State *L, int idx, const char *k)
#define lua_newtable(L)

References lua_absindex(), lua_getfield(), lua_istable, lua_newtable, lua_pop, lua_pushvalue(), and lua_setfield().

Referenced by createclibstable(), db_sethook(), luaL_openlibs(), luaL_requiref(), and luaopen_package().

◆ luaL_gsub()

LUALIB_API const char * luaL_gsub ( lua_State * L,
const char * s,
const char * p,
const char * r )

Definition at line 902 of file lua-5.2.4/src/lauxlib.c.

903 {
904 const char *wild;
905 size_t l = strlen(p);
906 luaL_Buffer b;
907 luaL_buffinit(L, &b);
908 while ((wild = strstr(s, p)) != NULL) {
909 luaL_addlstring(&b, s, wild - s); /* push prefix */
910 luaL_addstring(&b, r); /* push replacement in place of pattern */
911 s = wild + l; /* continue after `p' */
912 }
913 luaL_addstring(&b, s); /* push last suffix */
914 luaL_pushresult(&b);
915 return lua_tostring(L, -1);
916}
LUALIB_API void luaL_pushresult(luaL_Buffer *B)
LUALIB_API void luaL_addstring(luaL_Buffer *B, const char *s)

References lua_tostring, luaL_addlstring(), luaL_addstring(), luaL_buffinit(), luaL_pushresult(), NULL, and s.

◆ luaL_len()

LUALIB_API int luaL_len ( lua_State * L,
int idx )

Definition at line 725 of file lua-5.2.4/src/lauxlib.c.

725 {
726 int l;
727 int isnum;
728 lua_len(L, idx);
729 l = (int)lua_tointegerx(L, -1, &isnum);
730 if (!isnum)
731 luaL_error(L, "object length is not a number");
732 lua_pop(L, 1); /* remove object */
733 return l;
734}
LUA_API void lua_len(lua_State *L, int idx)

References lua_len(), lua_pop, lua_tointegerx(), and luaL_error().

Referenced by addtoclib(), addtoclib(), gctm(), gctm(), gctm(), ll_addtoclib(), pushargs(), pushargs(), tconcat(), tunpack(), unpack(), and unpack().

◆ luaL_loadbufferx()

LUALIB_API int luaL_loadbufferx ( lua_State * L,
const char * buff,
size_t size,
const char * name,
const char * mode )

Definition at line 682 of file lua-5.2.4/src/lauxlib.c.

683 {
684 LoadS ls;
685 ls.s = buff;
686 ls.size = size;
687 return lua_load(L, getS, &ls, name, mode);
688}
LUA_API int lua_load(lua_State *L, lua_Reader reader, void *data, const char *chunkname)
static const char * getS(lua_State *L, void *ud, size_t *size)

References getS(), lua_load(), name, LoadS::s, and LoadS::size.

Referenced by luaB_load(), luaB_load(), and luaB_load().

◆ luaL_loadfilex()

LUALIB_API int luaL_loadfilex ( lua_State * L,
const char * filename,
const char * mode )

Definition at line 630 of file lua-5.2.4/src/lauxlib.c.

631 {
632 LoadF lf;
633 int status, readstatus;
634 int c;
635 int fnameindex = lua_gettop(L) + 1; /* index of filename on the stack */
636 if (filename == NULL) {
637 lua_pushliteral(L, "=stdin");
638 lf.f = stdin;
639 }
640 else {
641 lua_pushfstring(L, "@%s", filename);
642 lf.f = fopen(filename, "r");
643 if (lf.f == NULL) return errfile(L, "open", fnameindex);
644 }
645 if (skipcomment(&lf, &c)) /* read initial portion */
646 lf.buff[lf.n++] = '\n'; /* add line to correct line numbers */
647 if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */
648 lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */
649 if (lf.f == NULL) return errfile(L, "reopen", fnameindex);
650 skipcomment(&lf, &c); /* re-read initial portion */
651 }
652 if (c != EOF)
653 lf.buff[lf.n++] = c; /* 'c' is the first character of the stream */
654 status = lua_load(L, getF, &lf, lua_tostring(L, -1), mode);
655 readstatus = ferror(lf.f);
656 if (filename) fclose(lf.f); /* close file (even in case of errors) */
657 if (readstatus) {
658 lua_settop(L, fnameindex); /* ignore results from `lua_load' */
659 return errfile(L, "read", fnameindex);
660 }
661 lua_remove(L, fnameindex);
662 return status;
663}
LUA_API void lua_settop(lua_State *L, int idx)
LUA_API int lua_gettop(lua_State *L)
#define LUA_SIGNATURE
static int errfile(lua_State *L, const char *what, int fnameindex)
static int skipcomment(LoadF *lf, int *cp)
static const char * getF(lua_State *L, void *ud, size_t *size)

References LoadF::buff, errfile(), LoadF::f, getF(), lua_gettop(), lua_load(), lua_pushfstring(), lua_pushliteral, lua_remove, lua_settop(), LUA_SIGNATURE, lua_tostring, LoadF::n, NULL, and skipcomment().

Referenced by luaB_loadfile(), luaB_loadfile(), and luaB_loadfile().

◆ luaL_loadstring()

LUALIB_API int luaL_loadstring ( lua_State * L,
const char * s )

Definition at line 691 of file lua-5.2.4/src/lauxlib.c.

691 {
692 return luaL_loadbuffer(L, s, strlen(s), s);
693}
#define luaL_loadbuffer(L, s, sz, n)

References luaL_loadbuffer, and s.

◆ luaL_newmetatable()

LUALIB_API int luaL_newmetatable ( lua_State * L,
const char * tname )

Definition at line 272 of file lua-5.2.4/src/lauxlib.c.

272 {
273 luaL_getmetatable(L, tname); /* try to get metatable */
274 if (!lua_isnil(L, -1)) /* name already in use? */
275 return 0; /* leave previous value on top, but return 0 */
276 lua_pop(L, 1);
277 lua_newtable(L); /* create metatable */
278 lua_pushvalue(L, -1);
279 lua_setfield(L, LUA_REGISTRYINDEX, tname); /* registry.name = metatable */
280 return 1;
281}
#define luaL_getmetatable(L, n)
#define LUA_REGISTRYINDEX

References lua_isnil, lua_newtable, lua_pop, lua_pushvalue(), LUA_REGISTRYINDEX, lua_setfield(), and luaL_getmetatable.

◆ luaL_newstate()

LUALIB_API lua_State * luaL_newstate ( void )

Definition at line 937 of file lua-5.2.4/src/lauxlib.c.

937 {
939 if (L) lua_atpanic(L, &panic);
940 return L;
941}
LUA_API lua_CFunction lua_atpanic(lua_State *L, lua_CFunction panicf)
LUA_API lua_State * lua_newstate(lua_Alloc f, void *ud)
static int panic(lua_State *L)
static void * l_alloc(void *ud, void *ptr, size_t osize, size_t nsize)

References l_alloc(), lua_atpanic(), lua_newstate(), NULL, and panic().

◆ luaL_optinteger()

LUALIB_API lua_Integer luaL_optinteger ( lua_State * L,
int narg,
lua_Integer def )

Definition at line 407 of file lua-5.2.4/src/lauxlib.c.

408 {
409 return luaL_opt(L, luaL_checkinteger, narg, def);
410}
#define luaL_opt(L, f, n, d)
LUALIB_API lua_Integer luaL_checkinteger(lua_State *L, int narg)

References luaL_checkinteger(), and luaL_opt.

◆ luaL_optlstring()

LUALIB_API const char * luaL_optlstring ( lua_State * L,
int narg,
const char * def,
size_t * len )

Definition at line 364 of file lua-5.2.4/src/lauxlib.c.

365 {
366 if (lua_isnoneornil(L, narg)) {
367 if (len)
368 *len = (def ? strlen(def) : 0);
369 return def;
370 }
371 else return luaL_checklstring(L, narg, len);
372}
#define lua_isnoneornil(L, n)
LUALIB_API const char * luaL_checklstring(lua_State *L, int narg, size_t *len)

References lua_isnoneornil, and luaL_checklstring().

◆ luaL_optnumber()

LUALIB_API lua_Number luaL_optnumber ( lua_State * L,
int narg,
lua_Number def )

Definition at line 384 of file lua-5.2.4/src/lauxlib.c.

384 {
385 return luaL_opt(L, luaL_checknumber, narg, def);
386}
LUALIB_API lua_Number luaL_checknumber(lua_State *L, int narg)

References luaL_checknumber(), and luaL_opt.

◆ luaL_optunsigned()

LUALIB_API lua_Unsigned luaL_optunsigned ( lua_State * L,
int narg,
lua_Unsigned def )

Definition at line 413 of file lua-5.2.4/src/lauxlib.c.

414 {
415 return luaL_opt(L, luaL_checkunsigned, narg, def);
416}
LUALIB_API lua_Unsigned luaL_checkunsigned(lua_State *L, int narg)

References luaL_checkunsigned(), and luaL_opt.

◆ luaL_prepbuffsize()

LUALIB_API char * luaL_prepbuffsize ( luaL_Buffer * B,
size_t sz )

Definition at line 437 of file lua-5.2.4/src/lauxlib.c.

437 {
438 lua_State *L = B->L;
439 if (B->size - B->n < sz) { /* not enough space? */
440 char *newbuff;
441 size_t newsize = B->size * 2; /* double buffer size */
442 if (newsize - B->n < sz) /* not big enough? */
443 newsize = B->n + sz;
444 if (newsize < B->n || newsize - B->n < sz)
445 luaL_error(L, "buffer too large");
446 /* create larger buffer */
447 newbuff = (char *)lua_newuserdata(L, newsize * sizeof(char));
448 /* move content to new buffer */
449 memcpy(newbuff, B->b, B->n * sizeof(char));
450 if (buffonstack(B))
451 lua_remove(L, -2); /* remove old buffer */
452 B->b = newbuff;
453 B->size = newsize;
454 }
455 return &B->b[B->n];
456}
#define lua_newuserdata(L, s)

References luaL_Buffer::b, buffonstack, luaL_Buffer::L, lua_newuserdata, lua_remove, luaL_error(), luaL_Buffer::n, and luaL_Buffer::size.

Referenced by addliteral(), addliteral(), luaL_addlstring(), luaL_buffinitsize(), os_date(), os_date(), packint(), packint(), read_all(), read_chars(), read_chars(), read_chars(), str_format(), str_format(), str_format(), str_pack(), and str_pack().

◆ luaL_pushresult()

LUALIB_API void luaL_pushresult ( luaL_Buffer * B)

Definition at line 471 of file lua-5.2.4/src/lauxlib.c.

471 {
472 lua_State *L = B->L;
473 lua_pushlstring(L, B->b, B->n);
474 if (buffonstack(B))
475 lua_remove(L, -2); /* remove old buffer */
476}
LUA_API void lua_pushlstring(lua_State *L, const char *s, size_t len)

References luaL_Buffer::b, buffonstack, luaL_Buffer::L, lua_pushlstring(), lua_remove, and luaL_Buffer::n.

Referenced by luaL_gsub(), and luaL_pushresultsize().

◆ luaL_pushresultsize()

LUALIB_API void luaL_pushresultsize ( luaL_Buffer * B,
size_t sz )

◆ luaL_ref()

LUALIB_API int luaL_ref ( lua_State * L,
int t )

Definition at line 522 of file lua-5.2.4/src/lauxlib.c.

522 {
523 int ref;
524 if (lua_isnil(L, -1)) {
525 lua_pop(L, 1); /* remove from stack */
526 return LUA_REFNIL; /* `nil' has a unique fixed reference */
527 }
528 t = lua_absindex(L, t);
529 lua_rawgeti(L, t, freelist); /* get first free element */
530 ref = (int)lua_tointeger(L, -1); /* ref = t[freelist] */
531 lua_pop(L, 1); /* remove it from stack */
532 if (ref != 0) { /* any free element? */
533 lua_rawgeti(L, t, ref); /* remove it from list */
534 lua_rawseti(L, t, freelist); /* (t[freelist] = t[ref]) */
535 }
536 else /* no free elements */
537 ref = (int)lua_rawlen(L, t) + 1; /* get a new reference */
538 lua_rawseti(L, t, ref);
539 return ref;
540}
#define lua_rawlen(L, index)
Definition LuaXML_lib.c:42
LUA_API void lua_rawseti(lua_State *L, int idx, int n)
LUA_API void lua_rawgeti(lua_State *L, int idx, int n)
#define LUA_REFNIL
#define freelist

References freelist, lua_absindex(), lua_isnil, lua_pop, lua_rawgeti(), lua_rawlen, lua_rawseti(), LUA_REFNIL, and lua_tointeger.

◆ luaL_requiref()

LUALIB_API void luaL_requiref ( lua_State * L,
const char * modname,
lua_CFunction openf,
int glb )

Definition at line 886 of file lua-5.2.4/src/lauxlib.c.

887 {
888 lua_pushcfunction(L, openf);
889 lua_pushstring(L, modname); /* argument to open function */
890 lua_call(L, 1, 1); /* open module */
891 luaL_getsubtable(L, LUA_REGISTRYINDEX, "_LOADED");
892 lua_pushvalue(L, -2); /* make copy of module (call result) */
893 lua_setfield(L, -2, modname); /* _LOADED[modname] = module */
894 lua_pop(L, 1); /* remove _LOADED table */
895 if (glb) {
896 lua_pushvalue(L, -1); /* copy of 'mod' */
897 lua_setglobal(L, modname); /* _G[modname] = module */
898 }
899}
#define lua_pushcfunction(L, f)
#define lua_setglobal(L, s)
LUALIB_API int luaL_getsubtable(lua_State *L, int idx, const char *fname)

References lua_call, lua_pop, lua_pushcfunction, lua_pushstring(), lua_pushvalue(), LUA_REGISTRYINDEX, lua_setfield(), lua_setglobal, and luaL_getsubtable().

Referenced by luaL_openlibs(), and luaopen_lsqlite3().

◆ luaL_setfuncs()

LUALIB_API void luaL_setfuncs ( lua_State * L,
const luaL_Reg * l,
int nup )

Definition at line 848 of file lua-5.2.4/src/lauxlib.c.

848 {
850 luaL_checkstack(L, nup, "too many upvalues");
851 for (; l->name != NULL; l++) { /* fill the table with given functions */
852 int i;
853 for (i = 0; i < nup; i++) /* copy upvalues to the top */
854 lua_pushvalue(L, -nup);
855 lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */
856 lua_setfield(L, -(nup + 2), l->name);
857 }
858 lua_pop(L, nup); /* remove upvalues */
859}
LUA_API void lua_pushcclosure(lua_State *L, lua_CFunction fn, int n)
LUALIB_API void luaL_checkstack(lua_State *L, int space, const char *msg)
#define luaL_checkversion(L)
lua_CFunction func
const char * name

References luaL_Reg::func, lua_pop, lua_pushcclosure(), lua_pushvalue(), lua_setfield(), luaL_checkstack(), luaL_checkversion, luaL_Reg::name, and NULL.

Referenced by createmeta(), createmeta(), createmeta(), createmetatable(), luaopen_base(), luaopen_package(), luaopen_sqlitelib(), and setrandfunc().

◆ luaL_setmetatable()

LUALIB_API void luaL_setmetatable ( lua_State * L,
const char * tname )

Definition at line 284 of file lua-5.2.4/src/lauxlib.c.

284 {
285 luaL_getmetatable(L, tname);
286 lua_setmetatable(L, -2);
287}
LUA_API int lua_setmetatable(lua_State *L, int objindex)

References lua_setmetatable(), and luaL_getmetatable.

Referenced by newprefile(), newprefile(), and newprefile().

◆ luaL_testudata()

LUALIB_API void * luaL_testudata ( lua_State * L,
int ud,
const char * tname )

Definition at line 290 of file lua-5.2.4/src/lauxlib.c.

290 {
291 void *p = lua_touserdata(L, ud);
292 if (p != NULL) { /* value is a userdata? */
293 if (lua_getmetatable(L, ud)) { /* does it have a metatable? */
294 luaL_getmetatable(L, tname); /* get correct metatable */
295 if (!lua_rawequal(L, -1, -2)) /* not the same? */
296 p = NULL; /* value is a userdata with wrong metatable */
297 lua_pop(L, 2); /* remove both metatables */
298 return p;
299 }
300 }
301 return NULL; /* value is not a userdata with a metatable */
302}
LUA_API void * lua_touserdata(lua_State *L, int idx)

References lua_getmetatable(), lua_pop, lua_rawequal(), lua_touserdata(), luaL_getmetatable, and NULL.

Referenced by io_type(), io_type(), io_type(), and luaL_checkudata().

◆ luaL_tolstring()

LUALIB_API const char * luaL_tolstring ( lua_State * L,
int idx,
size_t * len )

Definition at line 737 of file lua-5.2.4/src/lauxlib.c.

737 {
738 if (!luaL_callmeta(L, idx, "__tostring")) { /* no metafield? */
739 switch (lua_type(L, idx)) {
740 case LUA_TNUMBER:
741 case LUA_TSTRING:
742 lua_pushvalue(L, idx);
743 break;
744 case LUA_TBOOLEAN:
745 lua_pushstring(L, (lua_toboolean(L, idx) ? "true" : "false"));
746 break;
747 case LUA_TNIL:
748 lua_pushliteral(L, "nil");
749 break;
750 default:
751 lua_pushfstring(L, "%s: %p", luaL_typename(L, idx),
752 lua_topointer(L, idx));
753 break;
754 }
755 }
756 return lua_tolstring(L, -1, len);
757}
LUA_API int lua_toboolean(lua_State *L, int idx)
LUA_API const void * lua_topointer(lua_State *L, int idx)
#define luaL_typename(L, i)
#define LUA_TBOOLEAN
#define LUA_TNIL
LUALIB_API int luaL_callmeta(lua_State *L, int obj, const char *event)

References lua_pushfstring(), lua_pushliteral, lua_pushstring(), lua_pushvalue(), LUA_TBOOLEAN, LUA_TNIL, LUA_TNUMBER, lua_toboolean(), lua_tolstring(), lua_topointer(), LUA_TSTRING, lua_type(), luaL_callmeta(), and luaL_typename.

Referenced by add_s(), addliteral(), addliteral(), db_debug(), get_prompt(), luaB_print(), luaB_tostring(), luaB_tostring(), luaB_tostring(), str_format(), str_format(), and str_format().

◆ luaL_traceback()

LUALIB_API void luaL_traceback ( lua_State * L,
lua_State * L1,
const char * msg,
int level )

Definition at line 116 of file lua-5.2.4/src/lauxlib.c.

117 {
118 lua_Debug ar;
119 int top = lua_gettop(L);
120 int numlevels = countlevels(L1);
121 int mark = (numlevels > LEVELS1 + LEVELS2) ? LEVELS1 : 0;
122 if (msg) lua_pushfstring(L, "%s\n", msg);
123 lua_pushliteral(L, "stack traceback:");
124 while (lua_getstack(L1, level++, &ar)) {
125 if (level == mark) { /* too many levels? */
126 lua_pushliteral(L, "\n\t..."); /* add a '...' */
127 level = numlevels - LEVELS2; /* and skip to last ones */
128 }
129 else {
130 lua_getinfo(L1, "Slnt", &ar);
131 lua_pushfstring(L, "\n\t%s:", ar.short_src);
132 if (ar.currentline > 0)
133 lua_pushfstring(L, "%d:", ar.currentline);
134 lua_pushliteral(L, " in ");
135 pushfuncname(L, &ar);
136 if (ar.istailcall)
137 lua_pushliteral(L, "\n\t(...tail calls...)");
138 lua_concat(L, lua_gettop(L) - top);
139 }
140 }
141 lua_concat(L, lua_gettop(L) - top);
142}
static void pushfuncname(lua_State *L, lua_Debug *ar)
static int countlevels(lua_State *L)
#define LEVELS2
#define LEVELS1
char short_src[LUA_IDSIZE]

References countlevels(), lua_Debug::currentline, lua_Debug::istailcall, LEVELS1, LEVELS2, lua_concat(), lua_getinfo(), lua_getstack(), lua_gettop(), lua_pushfstring(), lua_pushliteral, pushfuncname(), and lua_Debug::short_src.

Referenced by db_traceback(), db_traceback(), db_traceback(), msghandler(), msghandler(), and traceback().

◆ luaL_unref()

LUALIB_API void luaL_unref ( lua_State * L,
int t,
int ref )

Definition at line 543 of file lua-5.2.4/src/lauxlib.c.

543 {
544 if (ref >= 0) {
545 t = lua_absindex(L, t);
546 lua_rawgeti(L, t, freelist);
547 lua_rawseti(L, t, ref); /* t[ref] = t[freelist] */
548 lua_pushinteger(L, ref);
549 lua_rawseti(L, t, freelist); /* t[freelist] = ref */
550 }
551}

References freelist, lua_absindex(), lua_pushinteger(), lua_rawgeti(), and lua_rawseti().

◆ luaL_where()

LUALIB_API void luaL_where ( lua_State * L,
int level )

Definition at line 183 of file lua-5.2.4/src/lauxlib.c.

183 {
184 lua_Debug ar;
185 if (lua_getstack(L, level, &ar)) { /* check function at level */
186 lua_getinfo(L, "Sl", &ar); /* get info about it */
187 if (ar.currentline > 0) { /* is there info? */
188 lua_pushfstring(L, "%s:%d: ", ar.short_src, ar.currentline);
189 return;
190 }
191 }
192 lua_pushliteral(L, ""); /* else, no information available... */
193}

References lua_Debug::currentline, lua_getinfo(), lua_getstack(), lua_pushfstring(), lua_pushliteral, and lua_Debug::short_src.

Referenced by luaL_error().

◆ panic()

static int panic ( lua_State * L)
static

Definition at line 930 of file lua-5.2.4/src/lauxlib.c.

930 {
931 luai_writestringerror("PANIC: unprotected error in call to Lua API (%s)\n",
932 lua_tostring(L, -1));
933 return 0; /* return to Lua to abort */
934}
#define luai_writestringerror(s, p)

References lua_tostring, and luai_writestringerror.

Referenced by luaL_newstate().

◆ pushfuncname()

static void pushfuncname ( lua_State * L,
lua_Debug * ar )
static

Definition at line 83 of file lua-5.2.4/src/lauxlib.c.

83 {
84 if (*ar->namewhat != '\0') /* is there a name? */
85 lua_pushfstring(L, "function " LUA_QS, ar->name);
86 else if (*ar->what == 'm') /* main? */
87 lua_pushliteral(L, "main chunk");
88 else if (*ar->what == 'C') {
89 if (pushglobalfuncname(L, ar)) {
90 lua_pushfstring(L, "function " LUA_QS, lua_tostring(L, -1));
91 lua_remove(L, -2); /* remove name */
92 }
93 else
94 lua_pushliteral(L, "?");
95 }
96 else
97 lua_pushfstring(L, "function <%s:%d>", ar->short_src, ar->linedefined);
98}
const char * what

References lua_Debug::linedefined, lua_pushfstring(), lua_pushliteral, LUA_QS, lua_remove, lua_tostring, lua_Debug::name, lua_Debug::namewhat, pushglobalfuncname(), lua_Debug::short_src, and lua_Debug::what.

Referenced by luaL_traceback().

◆ pushglobalfuncname()

static int pushglobalfuncname ( lua_State * L,
lua_Debug * ar )
static

Definition at line 67 of file lua-5.2.4/src/lauxlib.c.

67 {
68 int top = lua_gettop(L);
69 lua_getinfo(L, "f", ar); /* push function */
71 if (findfield(L, top + 1, 2)) {
72 lua_copy(L, -1, top + 1); /* move name to proper place */
73 lua_pop(L, 2); /* remove pushed values */
74 return 1;
75 }
76 else {
77 lua_settop(L, top); /* remove function and global table */
78 return 0;
79 }
80}
LUA_API void lua_copy(lua_State *L, int fromidx, int toidx)
#define lua_pushglobaltable(L)

References findfield(), lua_copy(), lua_getinfo(), lua_gettop(), lua_pop, lua_pushglobaltable, and lua_settop().

Referenced by luaL_argerror(), and pushfuncname().

◆ skipBOM()

static int skipBOM ( LoadF * lf)
static

Definition at line 596 of file lua-5.2.4/src/lauxlib.c.

596 {
597 const char *p = "\xEF\xBB\xBF"; /* Utf8 BOM mark */
598 int c;
599 lf->n = 0;
600 do {
601 c = getc(lf->f);
602 if (c == EOF || c != *(const unsigned char *)p++) return c;
603 lf->buff[lf->n++] = c; /* to be read by the parser */
604 } while (*p != '\0');
605 lf->n = 0; /* prefix matched; discard it */
606 return getc(lf->f); /* return next character */
607}

References LoadF::buff, LoadF::f, and LoadF::n.

Referenced by skipcomment().

◆ skipcomment()

static int skipcomment ( LoadF * lf,
int * cp )
static

Definition at line 617 of file lua-5.2.4/src/lauxlib.c.

617 {
618 int c = *cp = skipBOM(lf);
619 if (c == '#') { /* first line is a comment (Unix exec. file)? */
620 do { /* skip first line */
621 c = getc(lf->f);
622 } while (c != EOF && c != '\n') ;
623 *cp = getc(lf->f); /* skip end-of-line, if present */
624 return 1; /* there was a comment */
625 }
626 else return 0; /* no comment */
627}
static int skipBOM(LoadF *lf)

References LoadF::f, and skipBOM().

Referenced by luaL_loadfilex().

◆ tag_error()

static void tag_error ( lua_State * L,
int narg,
int tag )
static

Definition at line 178 of file lua-5.2.4/src/lauxlib.c.

178 {
179 typeerror(L, narg, lua_typename(L, tag));
180}
LUA_API const char * lua_typename(lua_State *L, int t)

References lua_typename(), and typeerror().

Referenced by luaL_checkinteger(), luaL_checklstring(), luaL_checknumber(), luaL_checktype(), and luaL_checkunsigned().

◆ typeerror()

static int typeerror ( lua_State * L,
int narg,
const char * tname )
static

Definition at line 171 of file lua-5.2.4/src/lauxlib.c.

171 {
172 const char *msg = lua_pushfstring(L, "%s expected, got %s",
173 tname, luaL_typename(L, narg));
174 return luaL_argerror(L, narg, msg);
175}

References lua_pushfstring(), luaL_argerror(), and luaL_typename.

Referenced by luaL_checkudata(), and tag_error().