Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
lauxlib.c File Reference
#include "lprefix.h"
#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  UBox
 
struct  LoadF
 
struct  LoadS
 

Macros

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

Typedefs

typedef struct UBox UBox
 
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 lastlevel (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 arg, const char *extramsg)
 
static int typeerror (lua_State *L, int arg, const char *tname)
 
static void tag_error (lua_State *L, int arg, 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 arg, 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 arg, int t)
 
LUALIB_API void luaL_checkany (lua_State *L, int arg)
 
LUALIB_API const char * luaL_checklstring (lua_State *L, int arg, size_t *len)
 
LUALIB_API const char * luaL_optlstring (lua_State *L, int arg, const char *def, size_t *len)
 
LUALIB_API lua_Number luaL_checknumber (lua_State *L, int arg)
 
LUALIB_API lua_Number luaL_optnumber (lua_State *L, int arg, lua_Number def)
 
static void interror (lua_State *L, int arg)
 
LUALIB_API lua_Integer luaL_checkinteger (lua_State *L, int arg)
 
LUALIB_API lua_Integer luaL_optinteger (lua_State *L, int arg, lua_Integer def)
 
static void * resizebox (lua_State *L, int idx, size_t newsize)
 
static int boxgc (lua_State *L)
 
static void * newbox (lua_State *L, size_t newsize)
 
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 lua_Integer 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, size_t sz)
 

Macro Definition Documentation

◆ buffonstack

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

Definition at line 499 of file lua-5.3.6/src/lauxlib.c.

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

◆ freelist

#define freelist   0

Definition at line 592 of file lua-5.3.6/src/lauxlib.c.

Referenced by luaL_ref(), and luaL_unref().

◆ l_inspectstat

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

Definition at line 267 of file lua-5.3.6/src/lauxlib.c.

Referenced by luaL_execresult().

◆ lauxlib_c

#define lauxlib_c

Definition at line 7 of file lua-5.3.6/src/lauxlib.c.

◆ LEVELS1

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

Definition at line 37 of file lua-5.3.6/src/lauxlib.c.

Referenced by luaL_traceback().

◆ LEVELS2

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

Definition at line 38 of file lua-5.3.6/src/lauxlib.c.

Referenced by luaL_traceback().

◆ LUA_LIB

#define LUA_LIB

Definition at line 8 of file lua-5.3.6/src/lauxlib.c.

Typedef Documentation

◆ LoadF

typedef struct LoadF LoadF

◆ LoadS

typedef struct LoadS LoadS

◆ UBox

typedef struct UBox UBox

Function Documentation

◆ boxgc()

static int boxgc ( lua_State * L)
static

Definition at line 476 of file lua-5.3.6/src/lauxlib.c.

476 {
477 resizebox(L, 1, 0);
478 return 0;
479}
static void * resizebox(lua_State *L, int idx, size_t newsize)

References resizebox().

Referenced by newbox().

◆ errfile()

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

Definition at line 660 of file lua-5.3.6/src/lauxlib.c.

660 {
661 const char *serr = strerror(errno);
662 const char *filename = lua_tostring(L, fnameindex) + 1;
663 lua_pushfstring(L, "cannot %s %s: %s", what, filename, serr);
664 lua_remove(L, fnameindex);
665 return LUA_ERRFILE;
666}
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 46 of file lua-5.3.6/src/lauxlib.c.

46 {
47 if (level == 0 || !lua_istable(L, -1))
48 return 0; /* not found */
49 lua_pushnil(L); /* start 'next' loop */
50 while (lua_next(L, -2)) { /* for each pair in table */
51 if (lua_type(L, -2) == LUA_TSTRING) { /* ignore non-string keys */
52 if (lua_rawequal(L, objidx, -1)) { /* found object? */
53 lua_pop(L, 1); /* remove value (but keep name) */
54 return 1;
55 }
56 else if (findfield(L, objidx, level - 1)) { /* try recursively */
57 lua_remove(L, -2); /* remove table (but keep name) */
58 lua_pushliteral(L, ".");
59 lua_insert(L, -2); /* place '.' between the two names */
60 lua_concat(L, 3);
61 return 1;
62 }
63 }
64 lua_pop(L, 1); /* remove value */
65 }
66 return 0; /* not found */
67}
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 642 of file lua-5.3.6/src/lauxlib.c.

642 {
643 LoadF *lf = (LoadF *)ud;
644 (void)L; /* not used */
645 if (lf->n > 0) { /* are there pre-read characters to be read? */
646 *size = lf->n; /* return them (chars already in buffer) */
647 lf->n = 0; /* no more pre-read characters */
648 }
649 else { /* read a block from file */
650 /* 'fread' can return > 0 *and* set the EOF flag. If next call to
651 'getF' called 'fread', it might still wait for user input.
652 The next check avoids this problem. */
653 if (feof(lf->f)) return NULL;
654 *size = fread(lf->buff, 1, sizeof(lf->buff), lf->f); /* read block */
655 }
656 return lf->buff;
657}
#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 745 of file lua-5.3.6/src/lauxlib.c.

745 {
746 LoadS *ls = (LoadS *)ud;
747 (void)L; /* not used */
748 if (ls->size == 0) return NULL;
749 *size = ls->size;
750 ls->size = 0;
751 return ls->s;
752}
const char * s

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

Referenced by luaL_loadbufferx().

◆ interror()

static void interror ( lua_State * L,
int arg )
static

Definition at line 422 of file lua-5.3.6/src/lauxlib.c.

422 {
423 if (lua_isnumber(L, arg))
424 luaL_argerror(L, arg, "number has no integer representation");
425 else
427}
CURL_EXTERN int void * arg
Definition curl.h:2622
LUA_API int lua_isnumber(lua_State *L, int idx)
#define LUA_TNUMBER
static void tag_error(lua_State *L, int arg, int tag)
LUALIB_API int luaL_argerror(lua_State *L, int arg, const char *extramsg)

References arg, lua_isnumber(), LUA_TNUMBER, luaL_argerror(), and tag_error().

Referenced by luaL_checkinteger().

◆ l_alloc()

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

Definition at line 1008 of file lua-5.3.6/src/lauxlib.c.

1008 {
1009 (void)ud; (void)osize; /* not used */
1010 if (nsize == 0) {
1011 free(ptr);
1012 return NULL;
1013 }
1014 else { /* cannot fail when shrinking a block */
1015 void *newptr = realloc(ptr, nsize);
1016 if (newptr == NULL && ptr != NULL && nsize <= osize)
1017 return ptr; /* keep the original block */
1018 else /* no fail or not shrinking */
1019 return newptr; /* use the new block */
1020 }
1021}
#define realloc
Definition civetweb.c:1541
#define free
Definition civetweb.c:1542

References free, NULL, and realloc.

Referenced by luaL_newstate().

◆ lastlevel()

static int lastlevel ( lua_State * L)
static

Definition at line 110 of file lua-5.3.6/src/lauxlib.c.

110 {
111 lua_Debug ar;
112 int li = 1, le = 1;
113 /* find an upper bound */
114 while (lua_getstack(L, le, &ar)) { li = le; le *= 2; }
115 /* do a binary search */
116 while (li < le) {
117 int m = (li + le)/2;
118 if (lua_getstack(L, m, &ar)) li = m + 1;
119 else le = m;
120 }
121 return le - 1;
122}
LUA_API int lua_getstack(lua_State *L, int level, lua_Debug *ar)

References lua_getstack().

Referenced by luaL_traceback().

◆ luaL_addlstring()

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

Definition at line 528 of file lua-5.3.6/src/lauxlib.c.

528 {
529 if (l > 0) { /* avoid 'memcpy' when 's' can be NULL */
530 char *b = luaL_prepbuffsize(B, l);
531 memcpy(b, s, l * sizeof(char));
532 luaL_addsize(B, l);
533 }
534}
#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 537 of file lua-5.3.6/src/lauxlib.c.

537 {
538 luaL_addlstring(B, s, strlen(s));
539}
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 558 of file lua-5.3.6/src/lauxlib.c.

558 {
559 lua_State *L = B->L;
560 size_t l;
561 const char *s = lua_tolstring(L, -1, &l);
562 if (buffonstack(B))
563 lua_insert(L, -2); /* put value below buffer */
564 luaL_addlstring(B, s, l);
565 lua_remove(L, (buffonstack(B)) ? -2 : -1); /* remove value */
566}
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 arg,
const char * extramsg )

Definition at line 164 of file lua-5.3.6/src/lauxlib.c.

164 {
165 lua_Debug ar;
166 if (!lua_getstack(L, 0, &ar)) /* no stack frame? */
167 return luaL_error(L, "bad argument #%d (%s)", arg, extramsg);
168 lua_getinfo(L, "n", &ar);
169 if (strcmp(ar.namewhat, "method") == 0) {
170 arg--; /* do not count 'self' */
171 if (arg == 0) /* error is in the self argument itself? */
172 return luaL_error(L, "calling '%s' on bad self (%s)",
173 ar.name, extramsg);
174 }
175 if (ar.name == NULL)
176 ar.name = (pushglobalfuncname(L, &ar)) ? lua_tostring(L, -1) : "?";
177 return luaL_error(L, "bad argument #%d to '%s' (%s)",
178 arg, ar.name, extramsg);
179}
LUA_API int lua_getinfo(lua_State *L, const char *what, lua_Debug *ar)
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 arg, lua_getinfo(), lua_getstack(), lua_tostring, luaL_error(), lua_Debug::name, lua_Debug::namewhat, NULL, and pushglobalfuncname().

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

◆ luaL_buffinit()

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

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

569 {
570 B->L = L;
571 B->b = B->initb;
572 B->n = 0;
574}
#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 577 of file lua-5.3.6/src/lauxlib.c.

577 {
578 luaL_buffinit(L, B);
579 return luaL_prepbuffsize(B, sz);
580}
LUALIB_API void luaL_buffinit(lua_State *L, luaL_Buffer *B)

References luaL_buffinit(), and luaL_prepbuffsize().

◆ luaL_callmeta()

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

Definition at line 788 of file lua-5.3.6/src/lauxlib.c.

788 {
789 obj = lua_absindex(L, obj);
790 if (luaL_getmetafield(L, obj, event) == LUA_TNIL) /* no metafield? */
791 return 0;
792 lua_pushvalue(L, obj);
793 lua_call(L, 1, 1);
794 return 1;
795}
LUA_API void lua_pushvalue(lua_State *L, int idx)
#define LUA_TNIL
LUA_API int lua_absindex(lua_State *L, int idx)
#define lua_call(L, n, r)
LUALIB_API int luaL_getmetafield(lua_State *L, int obj, const char *event)

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

Referenced by luaL_tolstring().

◆ luaL_checkany()

LUALIB_API void luaL_checkany ( lua_State * L,
int arg )

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

384 {
385 if (lua_type(L, arg) == LUA_TNONE)
386 luaL_argerror(L, arg, "value expected");
387}
#define LUA_TNONE

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

◆ luaL_checkinteger()

LUALIB_API lua_Integer luaL_checkinteger ( lua_State * L,
int arg )

Definition at line 430 of file lua-5.3.6/src/lauxlib.c.

430 {
431 int isnum;
432 lua_Integer d = lua_tointegerx(L, arg, &isnum);
433 if (!isnum) {
434 interror(L, arg);
435 }
436 return d;
437}
LUA_INTEGER lua_Integer
LUA_API lua_Integer lua_tointegerx(lua_State *L, int idx, int *isnum)
static void interror(lua_State *L, int arg)

References arg, interror(), and lua_tointegerx().

Referenced by luaL_optinteger().

◆ luaL_checklstring()

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

Definition at line 390 of file lua-5.3.6/src/lauxlib.c.

390 {
391 const char *s = lua_tolstring(L, arg, len);
392 if (!s) tag_error(L, arg, LUA_TSTRING);
393 return s;
394}

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

Referenced by luaL_optlstring().

◆ luaL_checknumber()

LUALIB_API lua_Number luaL_checknumber ( lua_State * L,
int arg )

Definition at line 408 of file lua-5.3.6/src/lauxlib.c.

408 {
409 int isnum;
410 lua_Number d = lua_tonumberx(L, arg, &isnum);
411 if (!isnum)
413 return d;
414}
LUA_NUMBER lua_Number
LUA_API lua_Number lua_tonumberx(lua_State *L, int idx, int *isnum)

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

Referenced by luaL_optnumber().

◆ luaL_checkoption()

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

Definition at line 348 of file lua-5.3.6/src/lauxlib.c.

349 {
350 const char *name = (def) ? luaL_optstring(L, arg, def) :
352 int i;
353 for (i=0; lst[i]; i++)
354 if (strcmp(lst[i], name) == 0)
355 return i;
356 return luaL_argerror(L, arg,
357 lua_pushfstring(L, "invalid option '%s'", name));
358}
const char * name
Definition lsqlite3.c:2154
#define luaL_optstring(L, n, d)
#define luaL_checkstring(L, n)

References arg, lua_pushfstring(), 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 368 of file lua-5.3.6/src/lauxlib.c.

368 {
369 if (!lua_checkstack(L, space)) {
370 if (msg)
371 luaL_error(L, "stack overflow (%s)", msg);
372 else
373 luaL_error(L, "stack overflow");
374 }
375}
LUA_API int lua_checkstack(lua_State *L, int size)

References lua_checkstack(), and luaL_error().

Referenced by luaL_setfuncs(), and luaL_traceback().

◆ luaL_checktype()

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

Definition at line 378 of file lua-5.3.6/src/lauxlib.c.

378 {
379 if (lua_type(L, arg) != t)
380 tag_error(L, arg, t);
381}

References arg, lua_type(), and tag_error().

◆ luaL_checkudata()

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

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

333 {
334 void *p = luaL_testudata(L, ud, tname);
335 if (p == NULL) typeerror(L, ud, tname);
336 return p;
337}
LUALIB_API void * luaL_testudata(lua_State *L, int ud, const char *tname)
static int typeerror(lua_State *L, int arg, const char *tname)

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

◆ luaL_checkversion_()

LUALIB_API void luaL_checkversion_ ( lua_State * L,
lua_Number ver,
size_t sz )

Definition at line 1038 of file lua-5.3.6/src/lauxlib.c.

1038 {
1039 const lua_Number *v = lua_version(L);
1040 if (sz != LUAL_NUMSIZES) /* check numeric types */
1041 luaL_error(L, "core and library have incompatible numeric types");
1042 if (v != lua_version(NULL))
1043 luaL_error(L, "multiple Lua VMs detected");
1044 else if (*v != ver)
1045 luaL_error(L, "version mismatch: app. needs %f, Lua core provides %f",
1046 (LUAI_UACNUMBER)ver, (LUAI_UACNUMBER)*v);
1047}
#define LUAI_UACNUMBER
LUA_API const lua_Number * lua_version(lua_State *L)
#define LUAL_NUMSIZES

References lua_version(), LUAI_UACNUMBER, luaL_error(), LUAL_NUMSIZES, and NULL.

◆ luaL_error()

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

Definition at line 223 of file lua-5.3.6/src/lauxlib.c.

223 {
224 va_list argp;
225 va_start(argp, fmt);
226 luaL_where(L, 1);
227 lua_pushvfstring(L, fmt, argp);
228 va_end(argp);
229 lua_concat(L, 2);
230 return lua_error(L);
231}
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(), luaL_prepbuffsize(), luaL_tolstring(), and resizebox().

◆ luaL_execresult()

LUALIB_API int luaL_execresult ( lua_State * L,
int stat )

Definition at line 274 of file lua-5.3.6/src/lauxlib.c.

274 {
275 const char *what = "exit"; /* type of termination */
276 if (stat == -1) /* error? */
277 return luaL_fileresult(L, 0, NULL);
278 else {
279 l_inspectstat(stat, what); /* interpret result */
280 if (*what == 'e' && stat == 0) /* successful termination? */
281 lua_pushboolean(L, 1);
282 else
283 lua_pushnil(L);
284 lua_pushstring(L, what);
285 lua_pushinteger(L, stat);
286 return 3; /* return true/nil,what,code */
287 }
288}
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)
#define l_inspectstat(stat, what)
LUALIB_API int luaL_fileresult(lua_State *L, int stat, const char *fname)

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

◆ luaL_fileresult()

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

Definition at line 234 of file lua-5.3.6/src/lauxlib.c.

234 {
235 int en = errno; /* calls to Lua API may change this value */
236 if (stat) {
237 lua_pushboolean(L, 1);
238 return 1;
239 }
240 else {
241 lua_pushnil(L);
242 if (fname)
243 lua_pushfstring(L, "%s: %s", fname, strerror(en));
244 else
245 lua_pushstring(L, strerror(en));
246 lua_pushinteger(L, en);
247 return 3;
248 }
249}

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

Referenced by luaL_execresult().

◆ luaL_getmetafield()

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

Definition at line 772 of file lua-5.3.6/src/lauxlib.c.

772 {
773 if (!lua_getmetatable(L, obj)) /* no metatable? */
774 return LUA_TNIL;
775 else {
776 int tt;
777 lua_pushstring(L, event);
778 tt = lua_rawget(L, -2);
779 if (tt == LUA_TNIL) /* is metafield nil? */
780 lua_pop(L, 2); /* remove metatable and metafield */
781 else
782 lua_remove(L, -2); /* remove only metatable */
783 return tt; /* return metafield type */
784 }
785}
LUA_API void lua_rawget(lua_State *L, int idx)
LUA_API int lua_getmetatable(lua_State *L, int objindex)

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

Referenced by luaL_callmeta(), luaL_tolstring(), and typeerror().

◆ luaL_getsubtable()

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

Definition at line 951 of file lua-5.3.6/src/lauxlib.c.

951 {
952 if (lua_getfield(L, idx, fname) == LUA_TTABLE)
953 return 1; /* table already there */
954 else {
955 lua_pop(L, 1); /* remove previous result */
956 idx = lua_absindex(L, idx);
957 lua_newtable(L);
958 lua_pushvalue(L, -1); /* copy to be left at top */
959 lua_setfield(L, idx, fname); /* assign new table to field */
960 return 0; /* false, because did not find table there */
961 }
962}
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_TTABLE
#define lua_newtable(L)

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

Referenced by luaL_requiref().

◆ luaL_gsub()

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

Definition at line 991 of file lua-5.3.6/src/lauxlib.c.

992 {
993 const char *wild;
994 size_t l = strlen(p);
995 luaL_Buffer b;
996 luaL_buffinit(L, &b);
997 while ((wild = strstr(s, p)) != NULL) {
998 luaL_addlstring(&b, s, wild - s); /* push prefix */
999 luaL_addstring(&b, r); /* push replacement in place of pattern */
1000 s = wild + l; /* continue after 'p' */
1001 }
1002 luaL_addstring(&b, s); /* push last suffix */
1003 luaL_pushresult(&b);
1004 return lua_tostring(L, -1);
1005}
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 lua_Integer luaL_len ( lua_State * L,
int idx )

Definition at line 798 of file lua-5.3.6/src/lauxlib.c.

798 {
799 lua_Integer l;
800 int isnum;
801 lua_len(L, idx);
802 l = lua_tointegerx(L, -1, &isnum);
803 if (!isnum)
804 luaL_error(L, "object length is not an integer");
805 lua_pop(L, 1); /* remove object */
806 return l;
807}
LUA_API void lua_len(lua_State *L, int idx)

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

◆ 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 755 of file lua-5.3.6/src/lauxlib.c.

756 {
757 LoadS ls;
758 ls.s = buff;
759 ls.size = size;
760 return lua_load(L, getS, &ls, name, mode);
761}
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.

◆ luaL_loadfilex()

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

Definition at line 703 of file lua-5.3.6/src/lauxlib.c.

704 {
705 LoadF lf;
706 int status, readstatus;
707 int c;
708 int fnameindex = lua_gettop(L) + 1; /* index of filename on the stack */
709 if (filename == NULL) {
710 lua_pushliteral(L, "=stdin");
711 lf.f = stdin;
712 }
713 else {
714 lua_pushfstring(L, "@%s", filename);
715 lf.f = fopen(filename, "r");
716 if (lf.f == NULL) return errfile(L, "open", fnameindex);
717 }
718 if (skipcomment(&lf, &c)) /* read initial portion */
719 lf.buff[lf.n++] = '\n'; /* add line to correct line numbers */
720 if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */
721 lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */
722 if (lf.f == NULL) return errfile(L, "reopen", fnameindex);
723 skipcomment(&lf, &c); /* re-read initial portion */
724 }
725 if (c != EOF)
726 lf.buff[lf.n++] = c; /* 'c' is the first character of the stream */
727 status = lua_load(L, getF, &lf, lua_tostring(L, -1), mode);
728 readstatus = ferror(lf.f);
729 if (filename) fclose(lf.f); /* close file (even in case of errors) */
730 if (readstatus) {
731 lua_settop(L, fnameindex); /* ignore results from 'lua_load' */
732 return errfile(L, "read", fnameindex);
733 }
734 lua_remove(L, fnameindex);
735 return status;
736}
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().

◆ luaL_loadstring()

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

Definition at line 764 of file lua-5.3.6/src/lauxlib.c.

764 {
765 return luaL_loadbuffer(L, s, strlen(s), s);
766}
#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 299 of file lua-5.3.6/src/lauxlib.c.

299 {
300 if (luaL_getmetatable(L, tname) != LUA_TNIL) /* name already in use? */
301 return 0; /* leave previous value on top, but return 0 */
302 lua_pop(L, 1);
303 lua_createtable(L, 0, 2); /* create metatable */
304 lua_pushstring(L, tname);
305 lua_setfield(L, -2, "__name"); /* metatable.__name = tname */
306 lua_pushvalue(L, -1);
307 lua_setfield(L, LUA_REGISTRYINDEX, tname); /* registry.name = metatable */
308 return 1;
309}
LUA_API void lua_createtable(lua_State *L, int narray, int nrec)
#define luaL_getmetatable(L, n)
#define LUA_REGISTRYINDEX

References lua_createtable(), lua_pop, lua_pushstring(), lua_pushvalue(), LUA_REGISTRYINDEX, lua_setfield(), LUA_TNIL, and luaL_getmetatable.

Referenced by newbox().

◆ luaL_newstate()

LUALIB_API lua_State * luaL_newstate ( void )

Definition at line 1031 of file lua-5.3.6/src/lauxlib.c.

1031 {
1033 if (L) lua_atpanic(L, &panic);
1034 return L;
1035}
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 arg,
lua_Integer def )

Definition at line 440 of file lua-5.3.6/src/lauxlib.c.

441 {
442 return luaL_opt(L, luaL_checkinteger, arg, def);
443}
#define luaL_opt(L, f, n, d)
LUALIB_API lua_Integer luaL_checkinteger(lua_State *L, int arg)

References arg, luaL_checkinteger(), and luaL_opt.

◆ luaL_optlstring()

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

Definition at line 397 of file lua-5.3.6/src/lauxlib.c.

398 {
399 if (lua_isnoneornil(L, arg)) {
400 if (len)
401 *len = (def ? strlen(def) : 0);
402 return def;
403 }
404 else return luaL_checklstring(L, arg, len);
405}
#define lua_isnoneornil(L, n)
LUALIB_API const char * luaL_checklstring(lua_State *L, int arg, size_t *len)

References arg, lua_isnoneornil, and luaL_checklstring().

◆ luaL_optnumber()

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

Definition at line 417 of file lua-5.3.6/src/lauxlib.c.

417 {
418 return luaL_opt(L, luaL_checknumber, arg, def);
419}
LUALIB_API lua_Number luaL_checknumber(lua_State *L, int arg)

References arg, luaL_checknumber(), and luaL_opt.

◆ luaL_prepbuffsize()

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

Definition at line 505 of file lua-5.3.6/src/lauxlib.c.

505 {
506 lua_State *L = B->L;
507 if (B->size - B->n < sz) { /* not enough space? */
508 char *newbuff;
509 size_t newsize = B->size * 2; /* double buffer size */
510 if (newsize - B->n < sz) /* not big enough? */
511 newsize = B->n + sz;
512 if (newsize < B->n || newsize - B->n < sz)
513 luaL_error(L, "buffer too large");
514 /* create larger buffer */
515 if (buffonstack(B))
516 newbuff = (char *)resizebox(L, -1, newsize);
517 else { /* no buffer yet */
518 newbuff = (char *)newbox(L, newsize);
519 memcpy(newbuff, B->b, B->n * sizeof(char)); /* copy original content */
520 }
521 B->b = newbuff;
522 B->size = newsize;
523 }
524 return &B->b[B->n];
525}
static void * newbox(lua_State *L, size_t newsize)

References luaL_Buffer::b, buffonstack, luaL_Buffer::L, luaL_error(), luaL_Buffer::n, newbox(), resizebox(), and luaL_Buffer::size.

Referenced by luaL_addlstring(), and luaL_buffinitsize().

◆ luaL_pushresult()

LUALIB_API void luaL_pushresult ( luaL_Buffer * B)

Definition at line 542 of file lua-5.3.6/src/lauxlib.c.

542 {
543 lua_State *L = B->L;
544 lua_pushlstring(L, B->b, B->n);
545 if (buffonstack(B)) {
546 resizebox(L, -2, 0); /* delete old buffer */
547 lua_remove(L, -2); /* remove its header from the stack */
548 }
549}
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, luaL_Buffer::n, and resizebox().

Referenced by luaL_gsub(), and luaL_pushresultsize().

◆ luaL_pushresultsize()

LUALIB_API void luaL_pushresultsize ( luaL_Buffer * B,
size_t sz )

Definition at line 552 of file lua-5.3.6/src/lauxlib.c.

552 {
553 luaL_addsize(B, sz);
555}

References luaL_addsize, and luaL_pushresult().

◆ luaL_ref()

LUALIB_API int luaL_ref ( lua_State * L,
int t )

Definition at line 595 of file lua-5.3.6/src/lauxlib.c.

595 {
596 int ref;
597 if (lua_isnil(L, -1)) {
598 lua_pop(L, 1); /* remove from stack */
599 return LUA_REFNIL; /* 'nil' has a unique fixed reference */
600 }
601 t = lua_absindex(L, t);
602 lua_rawgeti(L, t, freelist); /* get first free element */
603 ref = (int)lua_tointeger(L, -1); /* ref = t[freelist] */
604 lua_pop(L, 1); /* remove it from stack */
605 if (ref != 0) { /* any free element? */
606 lua_rawgeti(L, t, ref); /* remove it from list */
607 lua_rawseti(L, t, freelist); /* (t[freelist] = t[ref]) */
608 }
609 else /* no free elements */
610 ref = (int)lua_rawlen(L, t) + 1; /* get a new reference */
611 lua_rawseti(L, t, ref);
612 return ref;
613}
#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 lua_isnil(L, n)
#define lua_tointeger(L, i)
#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 971 of file lua-5.3.6/src/lauxlib.c.

972 {
974 lua_getfield(L, -1, modname); /* LOADED[modname] */
975 if (!lua_toboolean(L, -1)) { /* package not already loaded? */
976 lua_pop(L, 1); /* remove field */
977 lua_pushcfunction(L, openf);
978 lua_pushstring(L, modname); /* argument to open function */
979 lua_call(L, 1, 1); /* call 'openf' to open module */
980 lua_pushvalue(L, -1); /* make copy of module (call result) */
981 lua_setfield(L, -3, modname); /* LOADED[modname] = module */
982 }
983 lua_remove(L, -2); /* remove LOADED table */
984 if (glb) {
985 lua_pushvalue(L, -1); /* copy of module */
986 lua_setglobal(L, modname); /* _G[modname] = module */
987 }
988}
LUA_API int lua_toboolean(lua_State *L, int idx)
#define lua_pushcfunction(L, f)
#define lua_setglobal(L, s)
LUALIB_API int luaL_getsubtable(lua_State *L, int idx, const char *fname)
#define LUA_LOADED_TABLE

References lua_call, lua_getfield(), LUA_LOADED_TABLE, lua_pop, lua_pushcfunction, lua_pushstring(), lua_pushvalue(), LUA_REGISTRYINDEX, lua_remove, lua_setfield(), lua_setglobal, lua_toboolean(), and luaL_getsubtable().

◆ luaL_setfuncs()

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

Definition at line 934 of file lua-5.3.6/src/lauxlib.c.

934 {
935 luaL_checkstack(L, nup, "too many upvalues");
936 for (; l->name != NULL; l++) { /* fill the table with given functions */
937 int i;
938 for (i = 0; i < nup; i++) /* copy upvalues to the top */
939 lua_pushvalue(L, -nup);
940 lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */
941 lua_setfield(L, -(nup + 2), l->name);
942 }
943 lua_pop(L, nup); /* remove upvalues */
944}
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)
lua_CFunction func
const char * name

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

◆ luaL_setmetatable()

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

Definition at line 312 of file lua-5.3.6/src/lauxlib.c.

312 {
313 luaL_getmetatable(L, tname);
314 lua_setmetatable(L, -2);
315}
LUA_API int lua_setmetatable(lua_State *L, int objindex)

References lua_setmetatable(), and luaL_getmetatable.

◆ luaL_testudata()

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

Definition at line 318 of file lua-5.3.6/src/lauxlib.c.

318 {
319 void *p = lua_touserdata(L, ud);
320 if (p != NULL) { /* value is a userdata? */
321 if (lua_getmetatable(L, ud)) { /* does it have a metatable? */
322 luaL_getmetatable(L, tname); /* get correct metatable */
323 if (!lua_rawequal(L, -1, -2)) /* not the same? */
324 p = NULL; /* value is a userdata with wrong metatable */
325 lua_pop(L, 2); /* remove both metatables */
326 return p;
327 }
328 }
329 return NULL; /* value is not a userdata with a metatable */
330}
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 luaL_checkudata().

◆ luaL_tolstring()

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

Definition at line 810 of file lua-5.3.6/src/lauxlib.c.

810 {
811 if (luaL_callmeta(L, idx, "__tostring")) { /* metafield? */
812 if (!lua_isstring(L, -1))
813 luaL_error(L, "'__tostring' must return a string");
814 }
815 else {
816 switch (lua_type(L, idx)) {
817 case LUA_TNUMBER: {
818 if (lua_isinteger(L, idx))
819 lua_pushfstring(L, "%I", (LUAI_UACINT)lua_tointeger(L, idx));
820 else
822 break;
823 }
824 case LUA_TSTRING:
825 lua_pushvalue(L, idx);
826 break;
827 case LUA_TBOOLEAN:
828 lua_pushstring(L, (lua_toboolean(L, idx) ? "true" : "false"));
829 break;
830 case LUA_TNIL:
831 lua_pushliteral(L, "nil");
832 break;
833 default: {
834 int tt = luaL_getmetafield(L, idx, "__name"); /* try name */
835 const char *kind = (tt == LUA_TSTRING) ? lua_tostring(L, -1) :
836 luaL_typename(L, idx);
837 lua_pushfstring(L, "%s: %p", kind, lua_topointer(L, idx));
838 if (tt != LUA_TNIL)
839 lua_remove(L, -2); /* remove '__name' */
840 break;
841 }
842 }
843 }
844 return lua_tolstring(L, -1, len);
845}
LUA_API int lua_isstring(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_tonumber(L, i)
LUA_API int lua_isinteger(lua_State *L, int idx)
LUALIB_API int luaL_callmeta(lua_State *L, int obj, const char *event)
#define LUAI_UACINT

References lua_isinteger(), lua_isstring(), lua_pushfstring(), lua_pushliteral, lua_pushstring(), lua_pushvalue(), lua_remove, LUA_TBOOLEAN, LUA_TNIL, LUA_TNUMBER, lua_toboolean(), lua_tointeger, lua_tolstring(), lua_tonumber, lua_topointer(), lua_tostring, LUA_TSTRING, lua_type(), LUAI_UACINT, LUAI_UACNUMBER, luaL_callmeta(), luaL_error(), luaL_getmetafield(), and luaL_typename.

◆ luaL_traceback()

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

Definition at line 125 of file lua-5.3.6/src/lauxlib.c.

126 {
127 lua_Debug ar;
128 int top = lua_gettop(L);
129 int last = lastlevel(L1);
130 int n1 = (last - level > LEVELS1 + LEVELS2) ? LEVELS1 : -1;
131 if (msg)
132 lua_pushfstring(L, "%s\n", msg);
133 luaL_checkstack(L, 10, NULL);
134 lua_pushliteral(L, "stack traceback:");
135 while (lua_getstack(L1, level++, &ar)) {
136 if (n1-- == 0) { /* too many levels? */
137 lua_pushliteral(L, "\n\t..."); /* add a '...' */
138 level = last - LEVELS2 + 1; /* and skip to last ones */
139 }
140 else {
141 lua_getinfo(L1, "Slnt", &ar);
142 lua_pushfstring(L, "\n\t%s:", ar.short_src);
143 if (ar.currentline > 0)
144 lua_pushfstring(L, "%d:", ar.currentline);
145 lua_pushliteral(L, " in ");
146 pushfuncname(L, &ar);
147 if (ar.istailcall)
148 lua_pushliteral(L, "\n\t(...tail calls...)");
149 lua_concat(L, lua_gettop(L) - top);
150 }
151 }
152 lua_concat(L, lua_gettop(L) - top);
153}
static void pushfuncname(lua_State *L, lua_Debug *ar)
#define LEVELS2
#define LEVELS1
static int lastlevel(lua_State *L)
char short_src[LUA_IDSIZE]

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

◆ luaL_unref()

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

Definition at line 616 of file lua-5.3.6/src/lauxlib.c.

616 {
617 if (ref >= 0) {
618 t = lua_absindex(L, t);
619 lua_rawgeti(L, t, freelist);
620 lua_rawseti(L, t, ref); /* t[ref] = t[freelist] */
621 lua_pushinteger(L, ref);
622 lua_rawseti(L, t, freelist); /* t[freelist] = ref */
623 }
624}

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 205 of file lua-5.3.6/src/lauxlib.c.

205 {
206 lua_Debug ar;
207 if (lua_getstack(L, level, &ar)) { /* check function at level */
208 lua_getinfo(L, "Sl", &ar); /* get info about it */
209 if (ar.currentline > 0) { /* is there info? */
210 lua_pushfstring(L, "%s:%d: ", ar.short_src, ar.currentline);
211 return;
212 }
213 }
214 lua_pushfstring(L, ""); /* else, no information available... */
215}

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

Referenced by luaL_error().

◆ newbox()

static void * newbox ( lua_State * L,
size_t newsize )
static

Definition at line 482 of file lua-5.3.6/src/lauxlib.c.

482 {
483 UBox *box = (UBox *)lua_newuserdata(L, sizeof(UBox));
484 box->box = NULL;
485 box->bsize = 0;
486 if (luaL_newmetatable(L, "LUABOX")) { /* creating metatable? */
488 lua_setfield(L, -2, "__gc"); /* metatable.__gc = boxgc */
489 }
490 lua_setmetatable(L, -2);
491 return resizebox(L, -1, newsize);
492}
static int boxgc(lua_State *L)
LUALIB_API int luaL_newmetatable(lua_State *L, const char *tname)
#define lua_newuserdata(L, s)

References UBox::box, boxgc(), UBox::bsize, lua_newuserdata, lua_pushcfunction, lua_setfield(), lua_setmetatable(), luaL_newmetatable(), NULL, and resizebox().

Referenced by luaL_prepbuffsize().

◆ panic()

static int panic ( lua_State * L)
static

Definition at line 1024 of file lua-5.3.6/src/lauxlib.c.

1024 {
1025 lua_writestringerror("PANIC: unprotected error in call to Lua API (%s)\n",
1026 lua_tostring(L, -1));
1027 return 0; /* return to Lua to abort */
1028}
#define lua_writestringerror(s, p)

References lua_tostring, and lua_writestringerror.

Referenced by luaL_newstate().

◆ pushfuncname()

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

Definition at line 94 of file lua-5.3.6/src/lauxlib.c.

94 {
95 if (pushglobalfuncname(L, ar)) { /* try first a global name */
96 lua_pushfstring(L, "function '%s'", lua_tostring(L, -1));
97 lua_remove(L, -2); /* remove name */
98 }
99 else if (*ar->namewhat != '\0') /* is there a name from code? */
100 lua_pushfstring(L, "%s '%s'", ar->namewhat, ar->name); /* use it */
101 else if (*ar->what == 'm') /* main? */
102 lua_pushliteral(L, "main chunk");
103 else if (*ar->what != 'C') /* for Lua functions, use <file:line> */
104 lua_pushfstring(L, "function <%s:%d>", ar->short_src, ar->linedefined);
105 else /* nothing left... */
106 lua_pushliteral(L, "?");
107}
const char * what

References lua_Debug::linedefined, lua_pushfstring(), lua_pushliteral, 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 73 of file lua-5.3.6/src/lauxlib.c.

73 {
74 int top = lua_gettop(L);
75 lua_getinfo(L, "f", ar); /* push function */
77 if (findfield(L, top + 1, 2)) {
78 const char *name = lua_tostring(L, -1);
79 if (strncmp(name, "_G.", 3) == 0) { /* name start with '_G.'? */
80 lua_pushstring(L, name + 3); /* push name without prefix */
81 lua_remove(L, -2); /* remove original name */
82 }
83 lua_copy(L, -1, top + 1); /* move name to proper place */
84 lua_pop(L, 2); /* remove pushed values */
85 return 1;
86 }
87 else {
88 lua_settop(L, top); /* remove function and global table */
89 return 0;
90 }
91}
LUA_API void lua_copy(lua_State *L, int fromidx, int toidx)

References findfield(), lua_copy(), lua_getfield(), lua_getinfo(), lua_gettop(), LUA_LOADED_TABLE, lua_pop, lua_pushstring(), LUA_REGISTRYINDEX, lua_remove, lua_settop(), lua_tostring, and name.

Referenced by luaL_argerror(), and pushfuncname().

◆ resizebox()

static void * resizebox ( lua_State * L,
int idx,
size_t newsize )
static

Definition at line 461 of file lua-5.3.6/src/lauxlib.c.

461 {
462 void *ud;
463 lua_Alloc allocf = lua_getallocf(L, &ud);
464 UBox *box = (UBox *)lua_touserdata(L, idx);
465 void *temp = allocf(ud, box->box, box->bsize, newsize);
466 if (temp == NULL && newsize > 0) { /* allocation error? */
467 resizebox(L, idx, 0); /* free buffer */
468 luaL_error(L, "not enough memory for buffer allocation");
469 }
470 box->box = temp;
471 box->bsize = newsize;
472 return temp;
473}
LUA_API lua_Alloc lua_getallocf(lua_State *L, void **ud)
void *(* lua_Alloc)(void *ud, void *ptr, size_t osize, size_t nsize)

References UBox::box, UBox::bsize, lua_getallocf(), lua_touserdata(), luaL_error(), NULL, and resizebox().

Referenced by boxgc(), luaL_prepbuffsize(), luaL_pushresult(), newbox(), and resizebox().

◆ skipBOM()

static int skipBOM ( LoadF * lf)
static

Definition at line 669 of file lua-5.3.6/src/lauxlib.c.

669 {
670 const char *p = "\xEF\xBB\xBF"; /* UTF-8 BOM mark */
671 int c;
672 lf->n = 0;
673 do {
674 c = getc(lf->f);
675 if (c == EOF || c != *(const unsigned char *)p++) return c;
676 lf->buff[lf->n++] = c; /* to be read by the parser */
677 } while (*p != '\0');
678 lf->n = 0; /* prefix matched; discard it */
679 return getc(lf->f); /* return next character */
680}

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

Referenced by skipcomment().

◆ skipcomment()

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

Definition at line 690 of file lua-5.3.6/src/lauxlib.c.

690 {
691 int c = *cp = skipBOM(lf);
692 if (c == '#') { /* first line is a comment (Unix exec. file)? */
693 do { /* skip first line */
694 c = getc(lf->f);
695 } while (c != EOF && c != '\n');
696 *cp = getc(lf->f); /* skip end-of-line, if present */
697 return 1; /* there was a comment */
698 }
699 else return 0; /* no comment */
700}
static int skipBOM(LoadF *lf)

References LoadF::f, and skipBOM().

Referenced by luaL_loadfilex().

◆ tag_error()

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

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

196 {
197 typeerror(L, arg, lua_typename(L, tag));
198}
LUA_API const char * lua_typename(lua_State *L, int t)

References arg, lua_typename(), and typeerror().

Referenced by interror(), luaL_checklstring(), luaL_checknumber(), and luaL_checktype().

◆ typeerror()

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

Definition at line 182 of file lua-5.3.6/src/lauxlib.c.

182 {
183 const char *msg;
184 const char *typearg; /* name for the type of the actual argument */
185 if (luaL_getmetafield(L, arg, "__name") == LUA_TSTRING)
186 typearg = lua_tostring(L, -1); /* use the given type name */
187 else if (lua_type(L, arg) == LUA_TLIGHTUSERDATA)
188 typearg = "light userdata"; /* special name for messages */
189 else
190 typearg = luaL_typename(L, arg); /* standard name */
191 msg = lua_pushfstring(L, "%s expected, got %s", tname, typearg);
192 return luaL_argerror(L, arg, msg);
193}
#define LUA_TLIGHTUSERDATA

References arg, lua_pushfstring(), LUA_TLIGHTUSERDATA, lua_tostring, LUA_TSTRING, lua_type(), luaL_argerror(), luaL_getmetafield(), and luaL_typename.

Referenced by luaL_checkudata(), and tag_error().