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 MAX_SIZET   ((size_t)(~(size_t)0))
 
#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)->init.b)
 
#define checkbufferlevel(B, idx)
 
#define freelist   (LUA_RIDX_LAST + 1)
 

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)
 
LUALIB_API int luaL_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)
 
static size_t newbuffsize (luaL_Buffer *B, size_t sz)
 
static char * prepbuffsize (luaL_Buffer *B, size_t sz, int boxidx)
 
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 void luaL_addgsub (luaL_Buffer *b, const char *s, const char *p, const char *r)
 
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)
 
static void warnfoff (void *ud, const char *message, int tocont)
 
static void warnfon (void *ud, const char *message, int tocont)
 
static void warnfcont (void *ud, const char *message, int tocont)
 
static int checkcontrol (lua_State *L, const char *message, int tocont)
 
LUALIB_API lua_StateluaL_newstate (void)
 
LUALIB_API void luaL_checkversion_ (lua_State *L, lua_Number ver, size_t sz)
 

Variables

static const luaL_Reg boxmt []
 

Macro Definition Documentation

◆ buffonstack

#define buffonstack ( B)    ((B)->b != (B)->init.b)

Definition at line 515 of file lua-5.4.3/src/lauxlib.c.

Referenced by luaL_pushresult(), and prepbuffsize().

◆ checkbufferlevel

#define checkbufferlevel ( B,
idx )
Value:
: lua_touserdata(B->L, idx) == (void*)B)
#define NULL
Definition gmacros.h:924
LUA_API void * lua_touserdata(lua_State *L, int idx)
#define lua_assert(c)
#define buffonstack(B)

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

522#define checkbufferlevel(B,idx) \
523 lua_assert(buffonstack(B) ? lua_touserdata(B->L, idx) != NULL \
524 : lua_touserdata(B->L, idx) == (void*)B)

Referenced by luaL_pushresult(), and prepbuffsize().

◆ freelist

#define freelist   (LUA_RIDX_LAST + 1)

Definition at line 653 of file lua-5.4.3/src/lauxlib.c.

Referenced by luaL_ref(), and luaL_unref().

◆ l_inspectstat

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

Definition at line 278 of file lua-5.4.3/src/lauxlib.c.

Referenced by luaL_execresult().

◆ lauxlib_c

#define lauxlib_c

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

◆ LEVELS1

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

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

Referenced by luaL_traceback().

◆ LEVELS2

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

Definition at line 44 of file lua-5.4.3/src/lauxlib.c.

Referenced by luaL_traceback().

◆ LUA_LIB

#define LUA_LIB

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

◆ MAX_SIZET

#define MAX_SIZET   ((size_t)(~(size_t)0))

Definition at line 32 of file lua-5.4.3/src/lauxlib.c.

Referenced by newbuffsize().

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

488 {
489 resizebox(L, 1, 0);
490 return 0;
491}
static void * resizebox(lua_State *L, int idx, size_t newsize)

References resizebox().

◆ checkcontrol()

static int checkcontrol ( lua_State * L,
const char * message,
int tocont )
static

Definition at line 1045 of file lua-5.4.3/src/lauxlib.c.

1045 {
1046 if (tocont || *(message++) != '@') /* not a control message? */
1047 return 0;
1048 else {
1049 if (strcmp(message, "off") == 0)
1050 lua_setwarnf(L, warnfoff, L); /* turn warnings off */
1051 else if (strcmp(message, "on") == 0)
1052 lua_setwarnf(L, warnfon, L); /* turn warnings on */
1053 return 1; /* it was a control message */
1054 }
1055}
void lua_setwarnf(lua_State *L, lua_WarnFunction f, void *ud)
static void warnfoff(void *ud, const char *message, int tocont)
static void warnfon(void *ud, const char *message, int tocont)

References lua_setwarnf(), warnfoff(), and warnfon().

Referenced by warnfoff(), and warnfon().

◆ errfile()

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

Definition at line 733 of file lua-5.4.3/src/lauxlib.c.

733 {
734 const char *serr = strerror(errno);
735 const char *filename = lua_tostring(L, fnameindex) + 1;
736 lua_pushfstring(L, "cannot %s %s: %s", what, filename, serr);
737 lua_remove(L, fnameindex);
738 return LUA_ERRFILE;
739}
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 52 of file lua-5.4.3/src/lauxlib.c.

52 {
53 if (level == 0 || !lua_istable(L, -1))
54 return 0; /* not found */
55 lua_pushnil(L); /* start 'next' loop */
56 while (lua_next(L, -2)) { /* for each pair in table */
57 if (lua_type(L, -2) == LUA_TSTRING) { /* ignore non-string keys */
58 if (lua_rawequal(L, objidx, -1)) { /* found object? */
59 lua_pop(L, 1); /* remove value (but keep name) */
60 return 1;
61 }
62 else if (findfield(L, objidx, level - 1)) { /* try recursively */
63 /* stack: lib_name, lib_table, field_name (top) */
64 lua_pushliteral(L, "."); /* place '.' between the two names */
65 lua_replace(L, -3); /* (in the slot occupied by table) */
66 lua_concat(L, 3); /* lib_name.field_name */
67 return 1;
68 }
69 }
70 lua_pop(L, 1); /* remove value */
71 }
72 return 0; /* not found */
73}
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)
#define lua_replace(L, idx)
static int findfield(lua_State *L, int objidx, int level)

References findfield(), lua_concat(), lua_istable, lua_next(), lua_pop, lua_pushliteral, lua_pushnil(), lua_rawequal(), lua_replace, 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 715 of file lua-5.4.3/src/lauxlib.c.

715 {
716 LoadF *lf = (LoadF *)ud;
717 (void)L; /* not used */
718 if (lf->n > 0) { /* are there pre-read characters to be read? */
719 *size = lf->n; /* return them (chars already in buffer) */
720 lf->n = 0; /* no more pre-read characters */
721 }
722 else { /* read a block from file */
723 /* 'fread' can return > 0 *and* set the EOF flag. If next call to
724 'getF' called 'fread', it might still wait for user input.
725 The next check avoids this problem. */
726 if (feof(lf->f)) return NULL;
727 *size = fread(lf->buff, 1, sizeof(lf->buff), lf->f); /* read block */
728 }
729 return lf->buff;
730}
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 818 of file lua-5.4.3/src/lauxlib.c.

818 {
819 LoadS *ls = (LoadS *)ud;
820 (void)L; /* not used */
821 if (ls->size == 0) return NULL;
822 *size = ls->size;
823 ls->size = 0;
824 return ls->s;
825}
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 434 of file lua-5.4.3/src/lauxlib.c.

434 {
435 if (lua_isnumber(L, arg))
436 luaL_argerror(L, arg, "number has no integer representation");
437 else
439}
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 1010 of file lua-5.4.3/src/lauxlib.c.

1010 {
1011 (void)ud; (void)osize; /* not used */
1012 if (nsize == 0) {
1013 free(ptr);
1014 return NULL;
1015 }
1016 else
1017 return realloc(ptr, nsize);
1018}
#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 116 of file lua-5.4.3/src/lauxlib.c.

116 {
117 lua_Debug ar;
118 int li = 1, le = 1;
119 /* find an upper bound */
120 while (lua_getstack(L, le, &ar)) { li = le; le *= 2; }
121 /* do a binary search */
122 while (li < le) {
123 int m = (li + le)/2;
124 if (lua_getstack(L, m, &ar)) li = m + 1;
125 else le = m;
126 }
127 return le - 1;
128}
LUA_API int lua_getstack(lua_State *L, int level, lua_Debug *ar)

References lua_getstack().

Referenced by luaL_traceback().

◆ luaL_addgsub()

LUALIB_API void luaL_addgsub ( luaL_Buffer * b,
const char * s,
const char * p,
const char * r )

Definition at line 987 of file lua-5.4.3/src/lauxlib.c.

988 {
989 const char *wild;
990 size_t l = strlen(p);
991 while ((wild = strstr(s, p)) != NULL) {
992 luaL_addlstring(b, s, wild - s); /* push prefix */
993 luaL_addstring(b, r); /* push replacement in place of pattern */
994 s = wild + l; /* continue after 'p' */
995 }
996 luaL_addstring(b, s); /* push last suffix */
997}
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)
CURL_EXTERN CURLMcode curl_socket_t s
Definition multi.h:318

References luaL_addlstring(), luaL_addstring(), NULL, and s.

Referenced by luaL_gsub(), pusherrornotfound(), and searchpath().

◆ luaL_addlstring()

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

Definition at line 579 of file lua-5.4.3/src/lauxlib.c.

579 {
580 if (l > 0) { /* avoid 'memcpy' when 's' can be NULL */
581 char *b = prepbuffsize(B, l, -1);
582 memcpy(b, s, l * sizeof(char));
583 luaL_addsize(B, l);
584 }
585}
#define luaL_addsize(B, n)
static char * prepbuffsize(luaL_Buffer *B, size_t sz, int boxidx)

References luaL_addsize, prepbuffsize(), and s.

Referenced by luaL_addgsub(), and luaL_addstring().

◆ luaL_addstring()

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

Definition at line 588 of file lua-5.4.3/src/lauxlib.c.

588 {
589 luaL_addlstring(B, s, strlen(s));
590}

References luaL_addlstring(), and s.

Referenced by luaL_addgsub(), and luaL_traceback().

◆ luaL_addvalue()

LUALIB_API void luaL_addvalue ( luaL_Buffer * B)

Definition at line 618 of file lua-5.4.3/src/lauxlib.c.

618 {
619 lua_State *L = B->L;
620 size_t len;
621 const char *s = lua_tolstring(L, -1, &len);
622 char *b = prepbuffsize(B, len, -2);
623 memcpy(b, s, len * sizeof(char));
624 luaL_addsize(B, len);
625 lua_pop(L, 1); /* pop string */
626}
LUA_API const char * lua_tolstring(lua_State *L, int idx, size_t *len)

References luaL_Buffer::L, lua_pop, lua_tolstring(), luaL_addsize, prepbuffsize(), and s.

Referenced by luaL_traceback().

◆ luaL_argerror()

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

Definition at line 175 of file lua-5.4.3/src/lauxlib.c.

175 {
176 lua_Debug ar;
177 if (!lua_getstack(L, 0, &ar)) /* no stack frame? */
178 return luaL_error(L, "bad argument #%d (%s)", arg, extramsg);
179 lua_getinfo(L, "n", &ar);
180 if (strcmp(ar.namewhat, "method") == 0) {
181 arg--; /* do not count 'self' */
182 if (arg == 0) /* error is in the self argument itself? */
183 return luaL_error(L, "calling '%s' on bad self (%s)",
184 ar.name, extramsg);
185 }
186 if (ar.name == NULL)
187 ar.name = (pushglobalfuncname(L, &ar)) ? lua_tostring(L, -1) : "?";
188 return luaL_error(L, "bad argument #%d to '%s' (%s)",
189 arg, ar.name, extramsg);
190}
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 luaL_typeerror().

◆ luaL_buffinit()

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

Definition at line 629 of file lua-5.4.3/src/lauxlib.c.

629 {
630 B->L = L;
631 B->b = B->init.b;
632 B->n = 0;
634 lua_pushlightuserdata(L, (void*)B); /* push placeholder */
635}
LUA_API void lua_pushlightuserdata(lua_State *L, void *p)
#define LUAL_BUFFERSIZE
union luaL_Buffer::@82 init

References luaL_Buffer::b, luaL_Buffer::init, luaL_Buffer::L, lua_pushlightuserdata(), LUAL_BUFFERSIZE, luaL_Buffer::n, and luaL_Buffer::size.

Referenced by luaL_buffinitsize(), luaL_gsub(), and luaL_traceback().

◆ luaL_buffinitsize()

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

Definition at line 638 of file lua-5.4.3/src/lauxlib.c.

638 {
639 luaL_buffinit(L, B);
640 return prepbuffsize(B, sz, -1);
641}
LUALIB_API void luaL_buffinit(lua_State *L, luaL_Buffer *B)

References luaL_buffinit(), and prepbuffsize().

◆ luaL_callmeta()

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

Definition at line 861 of file lua-5.4.3/src/lauxlib.c.

861 {
862 obj = lua_absindex(L, obj);
863 if (luaL_getmetafield(L, obj, event) == LUA_TNIL) /* no metafield? */
864 return 0;
865 lua_pushvalue(L, obj);
866 lua_call(L, 1, 1);
867 return 1;
868}
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 396 of file lua-5.4.3/src/lauxlib.c.

396 {
397 if (l_unlikely(lua_type(L, arg) == LUA_TNONE))
398 luaL_argerror(L, arg, "value expected");
399}
#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 442 of file lua-5.4.3/src/lauxlib.c.

442 {
443 int isnum;
444 lua_Integer d = lua_tointegerx(L, arg, &isnum);
445 if (l_unlikely(!isnum)) {
446 interror(L, arg);
447 }
448 return d;
449}
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 402 of file lua-5.4.3/src/lauxlib.c.

402 {
403 const char *s = lua_tolstring(L, arg, len);
404 if (l_unlikely(!s)) tag_error(L, arg, LUA_TSTRING);
405 return s;
406}

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

420 {
421 int isnum;
422 lua_Number d = lua_tonumberx(L, arg, &isnum);
423 if (l_unlikely(!isnum))
425 return d;
426}
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 360 of file lua-5.4.3/src/lauxlib.c.

361 {
362 const char *name = (def) ? luaL_optstring(L, arg, def) :
364 int i;
365 for (i=0; lst[i]; i++)
366 if (strcmp(lst[i], name) == 0)
367 return i;
368 return luaL_argerror(L, arg,
369 lua_pushfstring(L, "invalid option '%s'", name));
370}
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 380 of file lua-5.4.3/src/lauxlib.c.

380 {
381 if (l_unlikely(!lua_checkstack(L, space))) {
382 if (msg)
383 luaL_error(L, "stack overflow (%s)", msg);
384 else
385 luaL_error(L, "stack overflow");
386 }
387}
LUA_API int lua_checkstack(lua_State *L, int size)

References lua_checkstack(), and luaL_error().

Referenced by luaL_setfuncs().

◆ luaL_checktype()

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

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

390 {
391 if (l_unlikely(lua_type(L, arg) != t))
392 tag_error(L, arg, t);
393}

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

345 {
346 void *p = luaL_testudata(L, ud, tname);
347 luaL_argexpected(L, p != NULL, ud, tname);
348 return p;
349}
LUALIB_API void * luaL_testudata(lua_State *L, int ud, const char *tname)
#define luaL_argexpected(L, cond, arg, tname)

References luaL_argexpected, luaL_testudata(), and NULL.

◆ luaL_checkversion_()

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

Definition at line 1097 of file lua-5.4.3/src/lauxlib.c.

1097 {
1098 lua_Number v = lua_version(L);
1099 if (sz != LUAL_NUMSIZES) /* check numeric types */
1100 luaL_error(L, "core and library have incompatible numeric types");
1101 else if (v != ver)
1102 luaL_error(L, "version mismatch: app. needs %f, Lua core provides %f",
1104}
#define LUAI_UACNUMBER
LUA_API const lua_Number * lua_version(lua_State *L)
#define LUAL_NUMSIZES

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

◆ luaL_error()

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

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

234 {
235 va_list argp;
236 va_start(argp, fmt);
237 luaL_where(L, 1);
238 lua_pushvfstring(L, fmt, argp);
239 va_end(argp);
240 lua_concat(L, 2);
241 return lua_error(L);
242}
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_tolstring(), and newbuffsize().

◆ luaL_execresult()

LUALIB_API int luaL_execresult ( lua_State * L,
int stat )

Definition at line 285 of file lua-5.4.3/src/lauxlib.c.

285 {
286 if (stat != 0 && errno != 0) /* error with an 'errno'? */
287 return luaL_fileresult(L, 0, NULL);
288 else {
289 const char *what = "exit"; /* type of termination */
290 l_inspectstat(stat, what); /* interpret result */
291 if (*what == 'e' && stat == 0) /* successful termination? */
292 lua_pushboolean(L, 1);
293 else
294 luaL_pushfail(L);
295 lua_pushstring(L, what);
296 lua_pushinteger(L, stat);
297 return 3; /* return true/fail,what,code */
298 }
299}
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)
#define luaL_pushfail(L)

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

◆ luaL_fileresult()

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

Definition at line 245 of file lua-5.4.3/src/lauxlib.c.

245 {
246 int en = errno; /* calls to Lua API may change this value */
247 if (stat) {
248 lua_pushboolean(L, 1);
249 return 1;
250 }
251 else {
252 luaL_pushfail(L);
253 if (fname)
254 lua_pushfstring(L, "%s: %s", fname, strerror(en));
255 else
256 lua_pushstring(L, strerror(en));
257 lua_pushinteger(L, en);
258 return 3;
259 }
260}

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

Referenced by luaL_execresult().

◆ luaL_getmetafield()

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

Definition at line 845 of file lua-5.4.3/src/lauxlib.c.

845 {
846 if (!lua_getmetatable(L, obj)) /* no metatable? */
847 return LUA_TNIL;
848 else {
849 int tt;
850 lua_pushstring(L, event);
851 tt = lua_rawget(L, -2);
852 if (tt == LUA_TNIL) /* is metafield nil? */
853 lua_pop(L, 2); /* remove metatable and metafield */
854 else
855 lua_remove(L, -2); /* remove only metatable */
856 return tt; /* return metafield type */
857 }
858}
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 luaL_typeerror().

◆ luaL_getsubtable()

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

Definition at line 947 of file lua-5.4.3/src/lauxlib.c.

947 {
948 if (lua_getfield(L, idx, fname) == LUA_TTABLE)
949 return 1; /* table already there */
950 else {
951 lua_pop(L, 1); /* remove previous result */
952 idx = lua_absindex(L, idx);
953 lua_newtable(L);
954 lua_pushvalue(L, -1); /* copy to be left at top */
955 lua_setfield(L, idx, fname); /* assign new table to field */
956 return 0; /* false, because did not find table there */
957 }
958}
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 1000 of file lua-5.4.3/src/lauxlib.c.

1001 {
1002 luaL_Buffer b;
1003 luaL_buffinit(L, &b);
1004 luaL_addgsub(&b, s, p, r);
1005 luaL_pushresult(&b);
1006 return lua_tostring(L, -1);
1007}
LUALIB_API void luaL_pushresult(luaL_Buffer *B)
LUALIB_API void luaL_addgsub(luaL_Buffer *b, const char *s, const char *p, const char *r)

References lua_tostring, luaL_addgsub(), luaL_buffinit(), luaL_pushresult(), and s.

◆ luaL_len()

LUALIB_API lua_Integer luaL_len ( lua_State * L,
int idx )

Definition at line 871 of file lua-5.4.3/src/lauxlib.c.

871 {
872 lua_Integer l;
873 int isnum;
874 lua_len(L, idx);
875 l = lua_tointegerx(L, -1, &isnum);
876 if (l_unlikely(!isnum))
877 luaL_error(L, "object length is not an integer");
878 lua_pop(L, 1); /* remove object */
879 return l;
880}
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 828 of file lua-5.4.3/src/lauxlib.c.

829 {
830 LoadS ls;
831 ls.s = buff;
832 ls.size = size;
833 return lua_load(L, getS, &ls, name, mode);
834}
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 776 of file lua-5.4.3/src/lauxlib.c.

777 {
778 LoadF lf;
779 int status, readstatus;
780 int c;
781 int fnameindex = lua_gettop(L) + 1; /* index of filename on the stack */
782 if (filename == NULL) {
783 lua_pushliteral(L, "=stdin");
784 lf.f = stdin;
785 }
786 else {
787 lua_pushfstring(L, "@%s", filename);
788 lf.f = fopen(filename, "r");
789 if (lf.f == NULL) return errfile(L, "open", fnameindex);
790 }
791 if (skipcomment(&lf, &c)) /* read initial portion */
792 lf.buff[lf.n++] = '\n'; /* add line to correct line numbers */
793 if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */
794 lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */
795 if (lf.f == NULL) return errfile(L, "reopen", fnameindex);
796 skipcomment(&lf, &c); /* re-read initial portion */
797 }
798 if (c != EOF)
799 lf.buff[lf.n++] = c; /* 'c' is the first character of the stream */
800 status = lua_load(L, getF, &lf, lua_tostring(L, -1), mode);
801 readstatus = ferror(lf.f);
802 if (filename) fclose(lf.f); /* close file (even in case of errors) */
803 if (readstatus) {
804 lua_settop(L, fnameindex); /* ignore results from 'lua_load' */
805 return errfile(L, "read", fnameindex);
806 }
807 lua_remove(L, fnameindex);
808 return status;
809}
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 837 of file lua-5.4.3/src/lauxlib.c.

837 {
838 return luaL_loadbuffer(L, s, strlen(s), s);
839}
#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 311 of file lua-5.4.3/src/lauxlib.c.

311 {
312 if (luaL_getmetatable(L, tname) != LUA_TNIL) /* name already in use? */
313 return 0; /* leave previous value on top, but return 0 */
314 lua_pop(L, 1);
315 lua_createtable(L, 0, 2); /* create metatable */
316 lua_pushstring(L, tname);
317 lua_setfield(L, -2, "__name"); /* metatable.__name = tname */
318 lua_pushvalue(L, -1);
319 lua_setfield(L, LUA_REGISTRYINDEX, tname); /* registry.name = metatable */
320 return 1;
321}
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 1087 of file lua-5.4.3/src/lauxlib.c.

1087 {
1089 if (l_likely(L)) {
1090 lua_atpanic(L, &panic);
1091 lua_setwarnf(L, warnfoff, L); /* default is warnings off */
1092 }
1093 return L;
1094}
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(), lua_setwarnf(), NULL, panic(), and warnfoff().

◆ luaL_optinteger()

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

Definition at line 452 of file lua-5.4.3/src/lauxlib.c.

453 {
454 return luaL_opt(L, luaL_checkinteger, arg, def);
455}
#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 409 of file lua-5.4.3/src/lauxlib.c.

410 {
411 if (lua_isnoneornil(L, arg)) {
412 if (len)
413 *len = (def ? strlen(def) : 0);
414 return def;
415 }
416 else return luaL_checklstring(L, arg, len);
417}
#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 429 of file lua-5.4.3/src/lauxlib.c.

429 {
430 return luaL_opt(L, luaL_checknumber, arg, def);
431}
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 574 of file lua-5.4.3/src/lauxlib.c.

574 {
575 return prepbuffsize(B, sz, -1);
576}

References prepbuffsize().

◆ luaL_pushresult()

LUALIB_API void luaL_pushresult ( luaL_Buffer * B)

Definition at line 593 of file lua-5.4.3/src/lauxlib.c.

593 {
594 lua_State *L = B->L;
595 checkbufferlevel(B, -1);
596 lua_pushlstring(L, B->b, B->n);
597 if (buffonstack(B))
598 lua_closeslot(L, -2); /* close the box */
599 lua_remove(L, -2); /* remove box or placeholder from the stack */
600}
LUA_API void lua_pushlstring(lua_State *L, const char *s, size_t len)
LUA_API void lua_closeslot(lua_State *L, int idx)
#define checkbufferlevel(B, idx)

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

Referenced by luaL_gsub(), luaL_pushresultsize(), and luaL_traceback().

◆ luaL_pushresultsize()

LUALIB_API void luaL_pushresultsize ( luaL_Buffer * B,
size_t sz )

Definition at line 603 of file lua-5.4.3/src/lauxlib.c.

603 {
604 luaL_addsize(B, sz);
606}

References luaL_addsize, and luaL_pushresult().

◆ luaL_ref()

LUALIB_API int luaL_ref ( lua_State * L,
int t )

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

660 {
661 int ref;
662 if (lua_isnil(L, -1)) {
663 lua_pop(L, 1); /* remove from stack */
664 return LUA_REFNIL; /* 'nil' has a unique fixed reference */
665 }
666 t = lua_absindex(L, t);
667 if (lua_rawgeti(L, t, freelist) == LUA_TNIL) { /* first access? */
668 ref = 0; /* list is empty */
669 lua_pushinteger(L, 0); /* initialize as an empty list */
670 lua_rawseti(L, t, freelist); /* ref = t[freelist] = 0 */
671 }
672 else { /* already initialized */
674 ref = (int)lua_tointeger(L, -1); /* ref = t[freelist] */
675 }
676 lua_pop(L, 1); /* remove element from stack */
677 if (ref != 0) { /* any free element? */
678 lua_rawgeti(L, t, ref); /* remove it from list */
679 lua_rawseti(L, t, freelist); /* (t[freelist] = t[ref]) */
680 }
681 else /* no free elements */
682 ref = (int)lua_rawlen(L, t) + 1; /* get a new reference */
683 lua_rawseti(L, t, ref);
684 return ref;
685}
#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)
LUA_API int lua_isinteger(lua_State *L, int idx)
#define freelist

References freelist, lua_absindex(), lua_assert, lua_isinteger(), lua_isnil, lua_pop, lua_pushinteger(), lua_rawgeti(), lua_rawlen, lua_rawseti(), LUA_REFNIL, LUA_TNIL, and lua_tointeger.

◆ luaL_requiref()

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

Definition at line 967 of file lua-5.4.3/src/lauxlib.c.

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

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

926 {
927 luaL_checkstack(L, nup, "too many upvalues");
928 for (; l->name != NULL; l++) { /* fill the table with given functions */
929 if (l->func == NULL) /* place holder? */
930 lua_pushboolean(L, 0);
931 else {
932 int i;
933 for (i = 0; i < nup; i++) /* copy upvalues to the top */
934 lua_pushvalue(L, -nup);
935 lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */
936 }
937 lua_setfield(L, -(nup + 2), l->name);
938 }
939 lua_pop(L, nup); /* remove upvalues */
940}
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_pushboolean(), lua_pushcclosure(), lua_pushvalue(), lua_setfield(), luaL_checkstack(), luaL_Reg::name, and NULL.

Referenced by newbox().

◆ luaL_setmetatable()

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

Definition at line 324 of file lua-5.4.3/src/lauxlib.c.

324 {
325 luaL_getmetatable(L, tname);
326 lua_setmetatable(L, -2);
327}
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 330 of file lua-5.4.3/src/lauxlib.c.

330 {
331 void *p = lua_touserdata(L, ud);
332 if (p != NULL) { /* value is a userdata? */
333 if (lua_getmetatable(L, ud)) { /* does it have a metatable? */
334 luaL_getmetatable(L, tname); /* get correct metatable */
335 if (!lua_rawequal(L, -1, -2)) /* not the same? */
336 p = NULL; /* value is a userdata with wrong metatable */
337 lua_pop(L, 2); /* remove both metatables */
338 return p;
339 }
340 }
341 return NULL; /* value is not a userdata with a metatable */
342}

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

883 {
884 if (luaL_callmeta(L, idx, "__tostring")) { /* metafield? */
885 if (!lua_isstring(L, -1))
886 luaL_error(L, "'__tostring' must return a string");
887 }
888 else {
889 switch (lua_type(L, idx)) {
890 case LUA_TNUMBER: {
891 if (lua_isinteger(L, idx))
892 lua_pushfstring(L, "%I", (LUAI_UACINT)lua_tointeger(L, idx));
893 else
895 break;
896 }
897 case LUA_TSTRING:
898 lua_pushvalue(L, idx);
899 break;
900 case LUA_TBOOLEAN:
901 lua_pushstring(L, (lua_toboolean(L, idx) ? "true" : "false"));
902 break;
903 case LUA_TNIL:
904 lua_pushliteral(L, "nil");
905 break;
906 default: {
907 int tt = luaL_getmetafield(L, idx, "__name"); /* try name */
908 const char *kind = (tt == LUA_TSTRING) ? lua_tostring(L, -1) :
909 luaL_typename(L, idx);
910 lua_pushfstring(L, "%s: %p", kind, lua_topointer(L, idx));
911 if (tt != LUA_TNIL)
912 lua_remove(L, -2); /* remove '__name' */
913 break;
914 }
915 }
916 }
917 return lua_tolstring(L, -1, len);
918}
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)
#define LUAI_UACINT
LUALIB_API int luaL_callmeta(lua_State *L, int obj, const char *event)

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

132 {
133 luaL_Buffer b;
134 lua_Debug ar;
135 int last = lastlevel(L1);
136 int limit2show = (last - level > LEVELS1 + LEVELS2) ? LEVELS1 : -1;
137 luaL_buffinit(L, &b);
138 if (msg) {
139 luaL_addstring(&b, msg);
140 luaL_addchar(&b, '\n');
141 }
142 luaL_addstring(&b, "stack traceback:");
143 while (lua_getstack(L1, level++, &ar)) {
144 if (limit2show-- == 0) { /* too many levels? */
145 int n = last - level - LEVELS2 + 1; /* number of levels to skip */
146 lua_pushfstring(L, "\n\t...\t(skipping %d levels)", n);
147 luaL_addvalue(&b); /* add warning about skip */
148 level += n; /* and skip to last levels */
149 }
150 else {
151 lua_getinfo(L1, "Slnt", &ar);
152 if (ar.currentline <= 0)
153 lua_pushfstring(L, "\n\t%s: in ", ar.short_src);
154 else
155 lua_pushfstring(L, "\n\t%s:%d: in ", ar.short_src, ar.currentline);
156 luaL_addvalue(&b);
157 pushfuncname(L, &ar);
158 luaL_addvalue(&b);
159 if (ar.istailcall)
160 luaL_addstring(&b, "\n\t(...tail calls...)");
161 }
162 }
163 luaL_pushresult(&b);
164}
#define luaL_addchar(B, c)
static void pushfuncname(lua_State *L, lua_Debug *ar)
LUALIB_API void luaL_addvalue(luaL_Buffer *B)
#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_getinfo(), lua_getstack(), lua_pushfstring(), luaL_addchar, luaL_addstring(), luaL_addvalue(), luaL_buffinit(), luaL_pushresult(), pushfuncname(), and lua_Debug::short_src.

◆ luaL_typeerror()

LUALIB_API int luaL_typeerror ( lua_State * L,
int arg,
const char * tname )

Definition at line 193 of file lua-5.4.3/src/lauxlib.c.

193 {
194 const char *msg;
195 const char *typearg; /* name for the type of the actual argument */
196 if (luaL_getmetafield(L, arg, "__name") == LUA_TSTRING)
197 typearg = lua_tostring(L, -1); /* use the given type name */
198 else if (lua_type(L, arg) == LUA_TLIGHTUSERDATA)
199 typearg = "light userdata"; /* special name for messages */
200 else
201 typearg = luaL_typename(L, arg); /* standard name */
202 msg = lua_pushfstring(L, "%s expected, got %s", tname, typearg);
203 return luaL_argerror(L, arg, msg);
204}
#define LUA_TLIGHTUSERDATA

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

Referenced by tag_error().

◆ luaL_unref()

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

Definition at line 688 of file lua-5.4.3/src/lauxlib.c.

688 {
689 if (ref >= 0) {
690 t = lua_absindex(L, t);
691 lua_rawgeti(L, t, freelist);
693 lua_rawseti(L, t, ref); /* t[ref] = t[freelist] */
694 lua_pushinteger(L, ref);
695 lua_rawseti(L, t, freelist); /* t[freelist] = ref */
696 }
697}

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

◆ luaL_where()

LUALIB_API void luaL_where ( lua_State * L,
int level )

Definition at line 216 of file lua-5.4.3/src/lauxlib.c.

216 {
217 lua_Debug ar;
218 if (lua_getstack(L, level, &ar)) { /* check function at level */
219 lua_getinfo(L, "Sl", &ar); /* get info about it */
220 if (ar.currentline > 0) { /* is there info? */
221 lua_pushfstring(L, "%s:%d: ", ar.short_src, ar.currentline);
222 return;
223 }
224 }
225 lua_pushfstring(L, ""); /* else, no information available... */
226}

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)
static

Definition at line 501 of file lua-5.4.3/src/lauxlib.c.

501 {
502 UBox *box = (UBox *)lua_newuserdatauv(L, sizeof(UBox), 0);
503 box->box = NULL;
504 box->bsize = 0;
505 if (luaL_newmetatable(L, "_UBOX*")) /* creating metatable? */
506 luaL_setfuncs(L, boxmt, 0); /* set its metamethods */
507 lua_setmetatable(L, -2);
508}
LUA_API void * lua_newuserdatauv(lua_State *L, size_t size, int nuvalue)
LUALIB_API int luaL_newmetatable(lua_State *L, const char *tname)
LUALIB_API void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup)
static const luaL_Reg boxmt[]

References UBox::box, boxmt, UBox::bsize, lua_newuserdatauv(), lua_setmetatable(), luaL_newmetatable(), luaL_setfuncs(), and NULL.

Referenced by prepbuffsize().

◆ newbuffsize()

static size_t newbuffsize ( luaL_Buffer * B,
size_t sz )
static

Definition at line 531 of file lua-5.4.3/src/lauxlib.c.

531 {
532 size_t newsize = B->size * 2; /* double buffer size */
533 if (l_unlikely(MAX_SIZET - sz < B->n)) /* overflow in (B->n + sz)? */
534 return luaL_error(B->L, "buffer too large");
535 if (newsize < B->n + sz) /* double is not big enough? */
536 newsize = B->n + sz;
537 return newsize;
538}
#define MAX_SIZET

References luaL_Buffer::L, luaL_error(), MAX_SIZET, luaL_Buffer::n, and luaL_Buffer::size.

Referenced by prepbuffsize().

◆ panic()

static int panic ( lua_State * L)
static

Definition at line 1021 of file lua-5.4.3/src/lauxlib.c.

1021 {
1022 const char *msg = lua_tostring(L, -1);
1023 if (msg == NULL) msg = "error object is not a string";
1024 lua_writestringerror("PANIC: unprotected error in call to Lua API (%s)\n",
1025 msg);
1026 return 0; /* return to Lua to abort */
1027}
#define lua_writestringerror(s, p)

References lua_tostring, lua_writestringerror, and NULL.

Referenced by luaL_newstate().

◆ prepbuffsize()

static char * prepbuffsize ( luaL_Buffer * B,
size_t sz,
int boxidx )
static

Definition at line 546 of file lua-5.4.3/src/lauxlib.c.

546 {
547 checkbufferlevel(B, boxidx);
548 if (B->size - B->n >= sz) /* enough space? */
549 return B->b + B->n;
550 else {
551 lua_State *L = B->L;
552 char *newbuff;
553 size_t newsize = newbuffsize(B, sz);
554 /* create larger buffer */
555 if (buffonstack(B)) /* buffer already has a box? */
556 newbuff = (char *)resizebox(L, boxidx, newsize); /* resize it */
557 else { /* no box yet */
558 lua_remove(L, boxidx); /* remove placeholder */
559 newbox(L); /* create a new box */
560 lua_insert(L, boxidx); /* move box to its intended position */
561 lua_toclose(L, boxidx);
562 newbuff = (char *)resizebox(L, boxidx, newsize);
563 memcpy(newbuff, B->b, B->n * sizeof(char)); /* copy original content */
564 }
565 B->b = newbuff;
566 B->size = newsize;
567 return newbuff + B->n;
568 }
569}
#define lua_insert(L, idx)
LUA_API void lua_toclose(lua_State *L, int idx)
static void newbox(lua_State *L)
static size_t newbuffsize(luaL_Buffer *B, size_t sz)

References luaL_Buffer::b, buffonstack, checkbufferlevel, luaL_Buffer::L, lua_insert, lua_remove, lua_toclose(), luaL_Buffer::n, newbox(), newbuffsize(), resizebox(), and luaL_Buffer::size.

Referenced by luaL_addlstring(), luaL_addvalue(), luaL_buffinitsize(), and luaL_prepbuffsize().

◆ pushfuncname()

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

Definition at line 100 of file lua-5.4.3/src/lauxlib.c.

100 {
101 if (pushglobalfuncname(L, ar)) { /* try first a global name */
102 lua_pushfstring(L, "function '%s'", lua_tostring(L, -1));
103 lua_remove(L, -2); /* remove name */
104 }
105 else if (*ar->namewhat != '\0') /* is there a name from code? */
106 lua_pushfstring(L, "%s '%s'", ar->namewhat, ar->name); /* use it */
107 else if (*ar->what == 'm') /* main? */
108 lua_pushliteral(L, "main chunk");
109 else if (*ar->what != 'C') /* for Lua functions, use <file:line> */
110 lua_pushfstring(L, "function <%s:%d>", ar->short_src, ar->linedefined);
111 else /* nothing left... */
112 lua_pushliteral(L, "?");
113}
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 79 of file lua-5.4.3/src/lauxlib.c.

79 {
80 int top = lua_gettop(L);
81 lua_getinfo(L, "f", ar); /* push function */
83 if (findfield(L, top + 1, 2)) {
84 const char *name = lua_tostring(L, -1);
85 if (strncmp(name, LUA_GNAME ".", 3) == 0) { /* name start with '_G.'? */
86 lua_pushstring(L, name + 3); /* push name without prefix */
87 lua_remove(L, -2); /* remove original name */
88 }
89 lua_copy(L, -1, top + 1); /* copy name to proper place */
90 lua_settop(L, top + 1); /* remove table "loaded" and name copy */
91 return 1;
92 }
93 else {
94 lua_settop(L, top); /* remove function and global table */
95 return 0;
96 }
97}
LUA_API void lua_copy(lua_State *L, int fromidx, int toidx)
#define LUA_GNAME

References findfield(), lua_copy(), lua_getfield(), lua_getinfo(), lua_gettop(), LUA_GNAME, LUA_LOADED_TABLE, 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 473 of file lua-5.4.3/src/lauxlib.c.

473 {
474 void *ud;
475 lua_Alloc allocf = lua_getallocf(L, &ud);
476 UBox *box = (UBox *)lua_touserdata(L, idx);
477 void *temp = allocf(ud, box->box, box->bsize, newsize);
478 if (l_unlikely(temp == NULL && newsize > 0)) { /* allocation error? */
479 lua_pushliteral(L, "not enough memory");
480 lua_error(L); /* raise a memory error */
481 }
482 box->box = temp;
483 box->bsize = newsize;
484 return temp;
485}
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_error(), lua_getallocf(), lua_pushliteral, lua_touserdata(), and NULL.

Referenced by boxgc(), and prepbuffsize().

◆ skipBOM()

static int skipBOM ( LoadF * lf)
static

Definition at line 742 of file lua-5.4.3/src/lauxlib.c.

742 {
743 const char *p = "\xEF\xBB\xBF"; /* UTF-8 BOM mark */
744 int c;
745 lf->n = 0;
746 do {
747 c = getc(lf->f);
748 if (c == EOF || c != *(const unsigned char *)p++) return c;
749 lf->buff[lf->n++] = c; /* to be read by the parser */
750 } while (*p != '\0');
751 lf->n = 0; /* prefix matched; discard it */
752 return getc(lf->f); /* return next character */
753}

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

Referenced by skipcomment().

◆ skipcomment()

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

Definition at line 763 of file lua-5.4.3/src/lauxlib.c.

763 {
764 int c = *cp = skipBOM(lf);
765 if (c == '#') { /* first line is a comment (Unix exec. file)? */
766 do { /* skip first line */
767 c = getc(lf->f);
768 } while (c != EOF && c != '\n');
769 *cp = getc(lf->f); /* skip end-of-line, if present */
770 return 1; /* there was a comment */
771 }
772 else return 0; /* no comment */
773}
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 207 of file lua-5.4.3/src/lauxlib.c.

207 {
208 luaL_typeerror(L, arg, lua_typename(L, tag));
209}
LUA_API const char * lua_typename(lua_State *L, int t)
LUALIB_API int luaL_typeerror(lua_State *L, int arg, const char *tname)

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

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

◆ warnfcont()

static void warnfcont ( void * ud,
const char * message,
int tocont )
static

Definition at line 1067 of file lua-5.4.3/src/lauxlib.c.

1067 {
1068 lua_State *L = (lua_State *)ud;
1069 lua_writestringerror("%s", message); /* write message */
1070 if (tocont) /* not the last part? */
1071 lua_setwarnf(L, warnfcont, L); /* to be continued */
1072 else { /* last part */
1073 lua_writestringerror("%s", "\n"); /* finish message with end-of-line */
1074 lua_setwarnf(L, warnfon, L); /* next call is a new message */
1075 }
1076}
static void warnfcont(void *ud, const char *message, int tocont)

References lua_setwarnf(), lua_writestringerror, warnfcont(), and warnfon().

Referenced by warnfcont(), and warnfon().

◆ warnfoff()

static void warnfoff ( void * ud,
const char * message,
int tocont )
static

Definition at line 1058 of file lua-5.4.3/src/lauxlib.c.

1058 {
1059 checkcontrol((lua_State *)ud, message, tocont);
1060}
static int checkcontrol(lua_State *L, const char *message, int tocont)

References checkcontrol().

Referenced by checkcontrol(), and luaL_newstate().

◆ warnfon()

static void warnfon ( void * ud,
const char * message,
int tocont )
static

Definition at line 1079 of file lua-5.4.3/src/lauxlib.c.

1079 {
1080 if (checkcontrol((lua_State *)ud, message, tocont)) /* control message? */
1081 return; /* nothing else to be done */
1082 lua_writestringerror("%s", "Lua warning: "); /* start a new warning */
1083 warnfcont(ud, message, tocont); /* finish processing */
1084}

References checkcontrol(), lua_writestringerror, and warnfcont().

Referenced by checkcontrol(), and warnfcont().

Variable Documentation

◆ boxmt

const luaL_Reg boxmt[]
static
Initial value:
= {
{"__gc", boxgc},
{"__close", boxgc},
}
static int boxgc(lua_State *L)

Definition at line 494 of file lua-5.4.3/src/lauxlib.c.

494 { /* box metamethods */
495 {"__gc", boxgc},
496 {"__close", boxgc},
497 {NULL, NULL}
498};

Referenced by newbox().