Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
lobject.c File Reference
#include "lprefix.h"
#include <locale.h>
#include <math.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "lua.h"
#include "lctype.h"
#include "ldebug.h"
#include "ldo.h"
#include "lmem.h"
#include "lobject.h"
#include "lstate.h"
#include "lstring.h"
#include "lvm.h"

Go to the source code of this file.

Data Structures

struct  BuffFS
 

Macros

#define lobject_c
 
#define LUA_CORE
 
#define L_MAXLENNUM   200
 
#define MAXBY10   cast(lua_Unsigned, LUA_MAXINTEGER / 10)
 
#define MAXLASTD   cast_int(LUA_MAXINTEGER % 10)
 
#define MAXNUMBER2STR   44
 
#define BUFVFS   200
 
#define addsize(b, sz)   ((b)->blen += (sz))
 
#define RETS   "..."
 
#define PRE   "[string \""
 
#define POS   "\"]"
 
#define addstr(a, b, l)   ( memcpy(a,b,(l) * sizeof(char)), a += (l) )
 

Typedefs

typedef struct BuffFS BuffFS
 

Functions

int luaO_ceillog2 (unsigned int x)
 
static lua_Integer intarith (lua_State *L, int op, lua_Integer v1, lua_Integer v2)
 
static lua_Number numarith (lua_State *L, int op, lua_Number v1, lua_Number v2)
 
int luaO_rawarith (lua_State *L, int op, const TValue *p1, const TValue *p2, TValue *res)
 
void luaO_arith (lua_State *L, int op, const TValue *p1, const TValue *p2, StkId res)
 
int luaO_hexavalue (int c)
 
static int isneg (const char **s)
 
static const char * l_str2dloc (const char *s, lua_Number *result, int mode)
 
static const char * l_str2d (const char *s, lua_Number *result)
 
static const char * l_str2int (const char *s, lua_Integer *result)
 
size_t luaO_str2num (const char *s, TValue *o)
 
int luaO_utf8esc (char *buff, unsigned long x)
 
static int tostringbuff (TValue *obj, char *buff)
 
void luaO_tostring (lua_State *L, TValue *obj)
 
static void pushstr (BuffFS *buff, const char *str, size_t l)
 
static void clearbuff (BuffFS *buff)
 
static char * getbuff (BuffFS *buff, int sz)
 
static void addstr2buff (BuffFS *buff, const char *str, size_t slen)
 
static void addnum2buff (BuffFS *buff, TValue *num)
 
const char * luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp)
 
const char * luaO_pushfstring (lua_State *L, const char *fmt,...)
 
void luaO_chunkid (char *out, const char *source, size_t srclen)
 

Macro Definition Documentation

◆ addsize

#define addsize ( b,
sz )   ((b)->blen += (sz))

Definition at line 436 of file lua-5.4.3/src/lobject.c.

Referenced by addnum2buff(), addstr2buff(), and luaO_pushvfstring().

◆ addstr

#define addstr ( a,
b,
l )   ( memcpy(a,b,(l) * sizeof(char)), a += (l) )

Definition at line 555 of file lua-5.4.3/src/lobject.c.

Referenced by luaO_chunkid().

◆ BUFVFS

#define BUFVFS   200

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

Referenced by addstr2buff(), and getbuff().

◆ L_MAXLENNUM

#define L_MAXLENNUM   200

Definition at line 220 of file lua-5.4.3/src/lobject.c.

Referenced by l_str2d().

◆ lobject_c

#define lobject_c

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

◆ LUA_CORE

#define LUA_CORE

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

◆ MAXBY10

#define MAXBY10   cast(lua_Unsigned, LUA_MAXINTEGER / 10)

Definition at line 273 of file lua-5.4.3/src/lobject.c.

Referenced by l_str2int().

◆ MAXLASTD

#define MAXLASTD   cast_int(LUA_MAXINTEGER % 10)

Definition at line 274 of file lua-5.4.3/src/lobject.c.

Referenced by l_str2int().

◆ MAXNUMBER2STR

#define MAXNUMBER2STR   44

Definition at line 349 of file lua-5.4.3/src/lobject.c.

Referenced by addnum2buff(), luaO_tostring(), and tostringbuff().

◆ POS

#define POS   "\"]"

Definition at line 553 of file lua-5.4.3/src/lobject.c.

Referenced by luaO_chunkid().

◆ PRE

#define PRE   "[string \""

Definition at line 552 of file lua-5.4.3/src/lobject.c.

Referenced by luaO_chunkid().

◆ RETS

#define RETS   "..."

Definition at line 551 of file lua-5.4.3/src/lobject.c.

Referenced by luaO_chunkid().

Typedef Documentation

◆ BuffFS

typedef struct BuffFS BuffFS

Function Documentation

◆ addnum2buff()

static void addnum2buff ( BuffFS * buff,
TValue * num )
static

Definition at line 459 of file lua-5.4.3/src/lobject.c.

459 {
460 char *numbuff = getbuff(buff, MAXNUMBER2STR);
461 int len = tostringbuff(num, numbuff); /* format number into 'numbuff' */
462 addsize(buff, len);
463}
#define MAXNUMBER2STR
static char * getbuff(BuffFS *buff, int sz)
#define addsize(b, sz)
static int tostringbuff(TValue *obj, char *buff)

References addsize, getbuff(), MAXNUMBER2STR, and tostringbuff().

Referenced by luaO_pushvfstring().

◆ addstr2buff()

static void addstr2buff ( BuffFS * buff,
const char * str,
size_t slen )
static

Definition at line 443 of file lua-5.4.3/src/lobject.c.

443 {
444 if (slen <= BUFVFS) { /* does string fit into buffer? */
445 char *bf = getbuff(buff, cast_int(slen));
446 memcpy(bf, str, slen); /* add string to buffer */
447 addsize(buff, cast_int(slen));
448 }
449 else { /* string larger than buffer */
450 clearbuff(buff); /* string comes after buffer's content */
451 pushstr(buff, str, slen); /* push string */
452 }
453}
#define cast_int(i)
#define BUFVFS
static void clearbuff(BuffFS *buff)
static void pushstr(BuffFS *buff, const char *str, size_t l)

References addsize, BUFVFS, cast_int, clearbuff(), getbuff(), and pushstr().

Referenced by luaO_pushvfstring().

◆ clearbuff()

static void clearbuff ( BuffFS * buff)
static

Definition at line 418 of file lua-5.4.3/src/lobject.c.

418 {
419 pushstr(buff, buff->space, buff->blen); /* push buffer contents */
420 buff->blen = 0; /* space now is empty */
421}
char space[BUFVFS]

References BuffFS::blen, pushstr(), and BuffFS::space.

Referenced by addstr2buff(), getbuff(), and luaO_pushvfstring().

◆ getbuff()

static char * getbuff ( BuffFS * buff,
int sz )
static

Definition at line 428 of file lua-5.4.3/src/lobject.c.

428 {
429 lua_assert(buff->blen <= BUFVFS); lua_assert(sz <= BUFVFS);
430 if (sz > BUFVFS - buff->blen) /* not enough space? */
431 clearbuff(buff);
432 return buff->space + buff->blen;
433}
#define lua_assert(c)

References BuffFS::blen, BUFVFS, clearbuff(), lua_assert, and BuffFS::space.

Referenced by addnum2buff(), addstr2buff(), and luaO_pushvfstring().

◆ intarith()

static lua_Integer intarith ( lua_State * L,
int op,
lua_Integer v1,
lua_Integer v2 )
static

Definition at line 53 of file lua-5.4.3/src/lobject.c.

54 {
55 switch (op) {
56 case LUA_OPADD: return intop(+, v1, v2);
57 case LUA_OPSUB:return intop(-, v1, v2);
58 case LUA_OPMUL:return intop(*, v1, v2);
59 case LUA_OPMOD: return luaV_mod(L, v1, v2);
60 case LUA_OPIDIV: return luaV_idiv(L, v1, v2);
61 case LUA_OPBAND: return intop(&, v1, v2);
62 case LUA_OPBOR: return intop(|, v1, v2);
63 case LUA_OPBXOR: return intop(^, v1, v2);
64 case LUA_OPSHL: return luaV_shiftl(v1, v2);
65 case LUA_OPSHR: return luaV_shiftl(v1, -v2);
66 case LUA_OPUNM: return intop(-, 0, v1);
67 case LUA_OPBNOT: return intop(^, ~l_castS2U(0), v1);
68 default: lua_assert(0); return 0;
69 }
70}
#define LUA_OPSUB
#define LUA_OPMUL
#define LUA_OPMOD
#define LUA_OPADD
#define LUA_OPUNM
#define l_castS2U(i)
#define LUA_OPBXOR
#define LUA_OPSHL
#define LUA_OPBOR
#define LUA_OPSHR
#define LUA_OPBNOT
#define LUA_OPBAND
#define LUA_OPIDIV
lua_Integer luaV_shiftl(lua_Integer x, lua_Integer y)
lua_Integer luaV_mod(lua_State *L, lua_Integer m, lua_Integer n)
#define intop(op, v1, v2)
lua_Integer luaV_idiv(lua_State *L, lua_Integer m, lua_Integer n)

References intop, l_castS2U, lua_assert, LUA_OPADD, LUA_OPBAND, LUA_OPBNOT, LUA_OPBOR, LUA_OPBXOR, LUA_OPIDIV, LUA_OPMOD, LUA_OPMUL, LUA_OPSHL, LUA_OPSHR, LUA_OPSUB, LUA_OPUNM, luaV_idiv(), luaV_mod(), and luaV_shiftl().

Referenced by luaO_rawarith().

◆ isneg()

static int isneg ( const char ** s)
static

Definition at line 141 of file lua-5.4.3/src/lobject.c.

141 {
142 if (**s == '-') { (*s)++; return 1; }
143 else if (**s == '+') (*s)++;
144 return 0;
145}
CURL_EXTERN CURLMcode curl_socket_t s
Definition multi.h:318

References s.

Referenced by l_str2int().

◆ l_str2d()

static const char * l_str2d ( const char * s,
lua_Number * result )
static

Definition at line 251 of file lua-5.4.3/src/lobject.c.

251 {
252 const char *endptr;
253 const char *pmode = strpbrk(s, ".xXnN"); /* look for special chars */
254 int mode = pmode ? ltolower(cast_uchar(*pmode)) : 0;
255 if (mode == 'n') /* reject 'inf' and 'nan' */
256 return NULL;
257 endptr = l_str2dloc(s, result, mode); /* try to convert */
258 if (endptr == NULL) { /* failed? may be a different locale */
259 char buff[L_MAXLENNUM + 1];
260 const char *pdot = strchr(s, '.');
261 if (pdot == NULL || strlen(s) > L_MAXLENNUM)
262 return NULL; /* string too long or no dot; fail */
263 strcpy(buff, s); /* copy string to buffer */
264 buff[pdot - s] = lua_getlocaledecpoint(); /* correct decimal point */
265 endptr = l_str2dloc(buff, result, mode); /* try again */
266 if (endptr != NULL)
267 endptr = s + (endptr - buff); /* make relative to 's' */
268 }
269 return endptr;
270}
#define NULL
Definition gmacros.h:924
#define ltolower(c)
#define cast_uchar(i)
#define lua_getlocaledecpoint()
static const char * l_str2dloc(const char *s, lua_Number *result, int mode)
#define L_MAXLENNUM

References cast_uchar, L_MAXLENNUM, l_str2dloc(), ltolower, lua_getlocaledecpoint, NULL, and s.

Referenced by luaO_str2num().

◆ l_str2dloc()

static const char * l_str2dloc ( const char * s,
lua_Number * result,
int mode )
static

Definition at line 228 of file lua-5.4.3/src/lobject.c.

228 {
229 char *endptr;
230 *result = (mode == 'x') ? lua_strx2number(s, &endptr) /* try to convert */
231 : lua_str2number(s, &endptr);
232 if (endptr == s) return NULL; /* nothing recognized? */
233 while (lisspace(cast_uchar(*endptr))) endptr++; /* skip trailing spaces */
234 return (*endptr == '\0') ? endptr : NULL; /* OK iff no trailing chars */
235}
#define lua_str2number(s, p)
#define lisspace(c)
#define lua_strx2number(s, p)

References cast_uchar, lisspace, lua_str2number, lua_strx2number, NULL, and s.

Referenced by l_str2d().

◆ l_str2int()

static const char * l_str2int ( const char * s,
lua_Integer * result )
static

Definition at line 276 of file lua-5.4.3/src/lobject.c.

276 {
277 lua_Unsigned a = 0;
278 int empty = 1;
279 int neg;
280 while (lisspace(cast_uchar(*s))) s++; /* skip initial spaces */
281 neg = isneg(&s);
282 if (s[0] == '0' &&
283 (s[1] == 'x' || s[1] == 'X')) { /* hex? */
284 s += 2; /* skip '0x' */
285 for (; lisxdigit(cast_uchar(*s)); s++) {
286 a = a * 16 + luaO_hexavalue(*s);
287 empty = 0;
288 }
289 }
290 else { /* decimal */
291 for (; lisdigit(cast_uchar(*s)); s++) {
292 int d = *s - '0';
293 if (a >= MAXBY10 && (a > MAXBY10 || d > MAXLASTD + neg)) /* overflow? */
294 return NULL; /* do not accept it (as integer) */
295 a = a * 10 + d;
296 empty = 0;
297 }
298 }
299 while (lisspace(cast_uchar(*s))) s++; /* skip trailing spaces */
300 if (empty || *s != '\0') return NULL; /* something wrong in the numeral */
301 else {
302 *result = l_castU2S((neg) ? 0u - a : a);
303 return s;
304 }
305}
#define lisxdigit(c)
#define lisdigit(c)
LUA_UNSIGNED lua_Unsigned
#define l_castU2S(i)
static int isneg(const char **s)
#define MAXBY10
#define MAXLASTD
int luaO_hexavalue(int c)

References cast_uchar, isneg(), l_castU2S, lisdigit, lisspace, lisxdigit, luaO_hexavalue(), MAXBY10, MAXLASTD, NULL, and s.

Referenced by luaO_str2num().

◆ luaO_arith()

void luaO_arith ( lua_State * L,
int op,
const TValue * p1,
const TValue * p2,
StkId res )

Definition at line 126 of file lua-5.4.3/src/lobject.c.

127 {
128 if (!luaO_rawarith(L, op, p1, p2, s2v(res))) {
129 /* could not perform raw operation; try metamethod */
130 luaT_trybinTM(L, p1, p2, res, cast(TMS, (op - LUA_OPADD) + TM_ADD));
131 }
132}
#define cast(t, exp)
@ TM_ADD
void luaT_trybinTM(lua_State *L, const TValue *p1, const TValue *p2, StkId res, TMS event)
int luaO_rawarith(lua_State *L, int op, const TValue *p1, const TValue *p2, TValue *res)
#define s2v(o)

References cast, LUA_OPADD, luaO_rawarith(), luaT_trybinTM(), s2v, and TM_ADD.

◆ luaO_ceillog2()

int luaO_ceillog2 ( unsigned int x)

Definition at line 35 of file lua-5.4.3/src/lobject.c.

35 {
36 static const lu_byte log_2[256] = { /* log_2[i] = ceil(log2(i - 1)) */
37 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
38 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
39 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
40 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
41 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
42 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
43 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
44 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8
45 };
46 int l = 0;
47 x--;
48 while (x >= 256) { l += 8; x >>= 8; }
49 return l + log_2[x];
50}
unsigned char lu_byte

◆ luaO_chunkid()

void luaO_chunkid ( char * out,
const char * source,
size_t srclen )

Definition at line 557 of file lua-5.4.3/src/lobject.c.

557 {
558 size_t bufflen = LUA_IDSIZE; /* free space in buffer */
559 if (*source == '=') { /* 'literal' source */
560 if (srclen <= bufflen) /* small enough? */
561 memcpy(out, source + 1, srclen * sizeof(char));
562 else { /* truncate it */
563 addstr(out, source + 1, bufflen - 1);
564 *out = '\0';
565 }
566 }
567 else if (*source == '@') { /* file name */
568 if (srclen <= bufflen) /* small enough? */
569 memcpy(out, source + 1, srclen * sizeof(char));
570 else { /* add '...' before rest of name */
571 addstr(out, RETS, LL(RETS));
572 bufflen -= LL(RETS);
573 memcpy(out, source + 1 + srclen - bufflen, bufflen * sizeof(char));
574 }
575 }
576 else { /* string; format as [string "source"] */
577 const char *nl = strchr(source, '\n'); /* find first new line (if any) */
578 addstr(out, PRE, LL(PRE)); /* add prefix */
579 bufflen -= LL(PRE RETS POS) + 1; /* save space for prefix+suffix+'\0' */
580 if (srclen < bufflen && nl == NULL) { /* small one-line source? */
581 addstr(out, source, srclen); /* keep it */
582 }
583 else {
584 if (nl != NULL) srclen = nl - source; /* stop at first newline */
585 if (srclen > bufflen) srclen = bufflen;
586 addstr(out, source, srclen);
587 addstr(out, RETS, LL(RETS));
588 }
589 memcpy(out, POS, (LL(POS) + 1) * sizeof(char));
590 }
591}
#define bufflen(B)
#define LUA_IDSIZE
#define LL(x)
#define addstr(a, b, l)
#define PRE
#define POS
#define RETS

References addstr, bufflen, LL, LUA_IDSIZE, NULL, POS, PRE, and RETS.

◆ luaO_hexavalue()

int luaO_hexavalue ( int c)

Definition at line 135 of file lua-5.4.3/src/lobject.c.

135 {
136 if (lisdigit(c)) return c - '0';
137 else return (ltolower(c) - 'a') + 10;
138}

References lisdigit, and ltolower.

Referenced by l_str2int().

◆ luaO_pushfstring()

const char * luaO_pushfstring ( lua_State * L,
const char * fmt,
... )

Definition at line 539 of file lua-5.4.3/src/lobject.c.

539 {
540 const char *msg;
541 va_list argp;
542 va_start(argp, fmt);
543 msg = luaO_pushvfstring(L, fmt, argp);
544 va_end(argp);
545 return msg;
546}
const char * luaO_pushvfstring(lua_State *L, const char *fmt, va_list argp)

References luaO_pushvfstring().

◆ luaO_pushvfstring()

const char * luaO_pushvfstring ( lua_State * L,
const char * fmt,
va_list argp )

Definition at line 470 of file lua-5.4.3/src/lobject.c.

470 {
471 BuffFS buff; /* holds last part of the result */
472 const char *e; /* points to next '%' */
473 buff.pushed = buff.blen = 0;
474 buff.L = L;
475 while ((e = strchr(fmt, '%')) != NULL) {
476 addstr2buff(&buff, fmt, e - fmt); /* add 'fmt' up to '%' */
477 switch (*(e + 1)) { /* conversion specifier */
478 case 's': { /* zero-terminated string */
479 const char *s = va_arg(argp, char *);
480 if (s == NULL) s = "(null)";
481 addstr2buff(&buff, s, strlen(s));
482 break;
483 }
484 case 'c': { /* an 'int' as a character */
485 char c = cast_uchar(va_arg(argp, int));
486 addstr2buff(&buff, &c, sizeof(char));
487 break;
488 }
489 case 'd': { /* an 'int' */
490 TValue num;
491 setivalue(&num, va_arg(argp, int));
492 addnum2buff(&buff, &num);
493 break;
494 }
495 case 'I': { /* a 'lua_Integer' */
496 TValue num;
497 setivalue(&num, cast(lua_Integer, va_arg(argp, l_uacInt)));
498 addnum2buff(&buff, &num);
499 break;
500 }
501 case 'f': { /* a 'lua_Number' */
502 TValue num;
503 setfltvalue(&num, cast_num(va_arg(argp, l_uacNumber)));
504 addnum2buff(&buff, &num);
505 break;
506 }
507 case 'p': { /* a pointer */
508 const int sz = 3 * sizeof(void*) + 8; /* enough space for '%p' */
509 char *bf = getbuff(&buff, sz);
510 void *p = va_arg(argp, void *);
511 int len = lua_pointer2str(bf, sz, p);
512 addsize(&buff, len);
513 break;
514 }
515 case 'U': { /* a 'long' as a UTF-8 sequence */
516 char bf[UTF8BUFFSZ];
517 int len = luaO_utf8esc(bf, va_arg(argp, long));
518 addstr2buff(&buff, bf + UTF8BUFFSZ - len, len);
519 break;
520 }
521 case '%': {
522 addstr2buff(&buff, "%", 1);
523 break;
524 }
525 default: {
526 luaG_runerror(L, "invalid option '%%%c' to 'lua_pushfstring'",
527 *(e + 1));
528 }
529 }
530 fmt = e + 2; /* skip '%' and the specifier */
531 }
532 addstr2buff(&buff, fmt, strlen(fmt)); /* rest of 'fmt' */
533 clearbuff(&buff); /* empty buffer into the stack */
534 lua_assert(buff.pushed == 1);
535 return svalue(s2v(L->top - 1));
536}
void luaG_runerror(lua_State *L, const char *fmt,...)
LUAI_UACNUMBER l_uacNumber
#define cast_num(i)
#define svalue(o)
LUA_INTEGER lua_Integer
LUAI_UACINT l_uacInt
#define UTF8BUFFSZ
#define setfltvalue(obj, x)
#define setivalue(obj, x)
#define lua_pointer2str(buff, sz, p)
static void addnum2buff(BuffFS *buff, TValue *num)
static void addstr2buff(BuffFS *buff, const char *str, size_t slen)
int luaO_utf8esc(char *buff, unsigned long x)
lua_State * L

References addnum2buff(), addsize, addstr2buff(), BuffFS::blen, cast, cast_num, cast_uchar, clearbuff(), getbuff(), BuffFS::L, lua_assert, lua_pointer2str, luaG_runerror(), luaO_utf8esc(), NULL, BuffFS::pushed, s, s2v, setfltvalue, setivalue, svalue, lua_State::top, and UTF8BUFFSZ.

Referenced by luaO_pushfstring().

◆ luaO_rawarith()

int luaO_rawarith ( lua_State * L,
int op,
const TValue * p1,
const TValue * p2,
TValue * res )

Definition at line 89 of file lua-5.4.3/src/lobject.c.

90 {
91 switch (op) {
92 case LUA_OPBAND: case LUA_OPBOR: case LUA_OPBXOR:
93 case LUA_OPSHL: case LUA_OPSHR:
94 case LUA_OPBNOT: { /* operate only on integers */
96 if (tointegerns(p1, &i1) && tointegerns(p2, &i2)) {
97 setivalue(res, intarith(L, op, i1, i2));
98 return 1;
99 }
100 else return 0; /* fail */
101 }
102 case LUA_OPDIV: case LUA_OPPOW: { /* operate only on floats */
103 lua_Number n1; lua_Number n2;
104 if (tonumberns(p1, n1) && tonumberns(p2, n2)) {
105 setfltvalue(res, numarith(L, op, n1, n2));
106 return 1;
107 }
108 else return 0; /* fail */
109 }
110 default: { /* other operations */
111 lua_Number n1; lua_Number n2;
112 if (ttisinteger(p1) && ttisinteger(p2)) {
113 setivalue(res, intarith(L, op, ivalue(p1), ivalue(p2)));
114 return 1;
115 }
116 else if (tonumberns(p1, n1) && tonumberns(p2, n2)) {
117 setfltvalue(res, numarith(L, op, n1, n2));
118 return 1;
119 }
120 else return 0; /* fail */
121 }
122 }
123}
LUA_NUMBER lua_Number
#define LUA_OPPOW
#define LUA_OPDIV
#define ttisinteger(o)
#define ivalue(o)
static lua_Integer intarith(lua_State *L, int op, lua_Integer v1, lua_Integer v2)
static lua_Number numarith(lua_State *L, int op, lua_Number v1, lua_Number v2)
#define tointegerns(o, i)
#define tonumberns(o, n)

References intarith(), ivalue, LUA_OPBAND, LUA_OPBNOT, LUA_OPBOR, LUA_OPBXOR, LUA_OPDIV, LUA_OPPOW, LUA_OPSHL, LUA_OPSHR, numarith(), setfltvalue, setivalue, tointegerns, tonumberns, and ttisinteger.

Referenced by constfolding(), and luaO_arith().

◆ luaO_str2num()

size_t luaO_str2num ( const char * s,
TValue * o )

Definition at line 308 of file lua-5.4.3/src/lobject.c.

308 {
310 const char *e;
311 if ((e = l_str2int(s, &i)) != NULL) { /* try as an integer */
312 setivalue(o, i);
313 }
314 else if ((e = l_str2d(s, &n)) != NULL) { /* else try as a float */
315 setfltvalue(o, n);
316 }
317 else
318 return 0; /* conversion failed */
319 return (e - s) + 1; /* success; return string size */
320}
static const char * l_str2int(const char *s, lua_Integer *result)
static const char * l_str2d(const char *s, lua_Number *result)

References l_str2d(), l_str2int(), NULL, s, setfltvalue, and setivalue.

◆ luaO_tostring()

void luaO_tostring ( lua_State * L,
TValue * obj )

Definition at line 374 of file lua-5.4.3/src/lobject.c.

374 {
375 char buff[MAXNUMBER2STR];
376 int len = tostringbuff(obj, buff);
377 setsvalue(L, obj, luaS_newlstr(L, buff, len));
378}
#define setsvalue(L, obj, x)
TString * luaS_newlstr(lua_State *L, const char *str, size_t l)

References luaS_newlstr(), MAXNUMBER2STR, setsvalue, and tostringbuff().

◆ luaO_utf8esc()

int luaO_utf8esc ( char * buff,
unsigned long x )

Definition at line 323 of file lua-5.4.3/src/lobject.c.

323 {
324 int n = 1; /* number of bytes put in buffer (backwards) */
325 lua_assert(x <= 0x7FFFFFFFu);
326 if (x < 0x80) /* ascii? */
327 buff[UTF8BUFFSZ - 1] = cast_char(x);
328 else { /* need continuation bytes */
329 unsigned int mfb = 0x3f; /* maximum that fits in first byte */
330 do { /* add continuation bytes */
331 buff[UTF8BUFFSZ - (n++)] = cast_char(0x80 | (x & 0x3f));
332 x >>= 6; /* remove added bits */
333 mfb >>= 1; /* now there is one less bit available in first byte */
334 } while (x > mfb); /* still needs continuation byte? */
335 buff[UTF8BUFFSZ - n] = cast_char((~mfb << 1) | x); /* add first byte */
336 }
337 return n;
338}
#define cast_char(i)

References cast_char, lua_assert, and UTF8BUFFSZ.

Referenced by luaO_pushvfstring().

◆ numarith()

static lua_Number numarith ( lua_State * L,
int op,
lua_Number v1,
lua_Number v2 )
static

Definition at line 73 of file lua-5.4.3/src/lobject.c.

74 {
75 switch (op) {
76 case LUA_OPADD: return luai_numadd(L, v1, v2);
77 case LUA_OPSUB: return luai_numsub(L, v1, v2);
78 case LUA_OPMUL: return luai_nummul(L, v1, v2);
79 case LUA_OPDIV: return luai_numdiv(L, v1, v2);
80 case LUA_OPPOW: return luai_numpow(L, v1, v2);
81 case LUA_OPIDIV: return luai_numidiv(L, v1, v2);
82 case LUA_OPUNM: return luai_numunm(L, v1);
83 case LUA_OPMOD: return luaV_modf(L, v1, v2);
84 default: lua_assert(0); return 0;
85 }
86}
#define luai_nummul(L, a, b)
#define luai_numdiv(L, a, b)
#define luai_numpow(L, a, b)
#define luai_numunm(L, a)
#define luai_numsub(L, a, b)
#define luai_numidiv(L, a, b)
#define luai_numadd(L, a, b)
lua_Number luaV_modf(lua_State *L, lua_Number m, lua_Number n)

References lua_assert, LUA_OPADD, LUA_OPDIV, LUA_OPIDIV, LUA_OPMOD, LUA_OPMUL, LUA_OPPOW, LUA_OPSUB, LUA_OPUNM, luai_numadd, luai_numdiv, luai_numidiv, luai_nummul, luai_numpow, luai_numsub, luai_numunm, and luaV_modf().

Referenced by luaO_rawarith().

◆ pushstr()

static void pushstr ( BuffFS * buff,
const char * str,
size_t l )
static

Definition at line 405 of file lua-5.4.3/src/lobject.c.

405 {
406 lua_State *L = buff->L;
407 setsvalue2s(L, L->top, luaS_newlstr(L, str, l));
408 L->top++; /* may use one extra slot */
409 buff->pushed++;
410 luaV_concat(L, buff->pushed); /* join partial results into one */
411 buff->pushed = 1;
412}
#define setsvalue2s
void luaV_concat(lua_State *L, int total, int last)

References BuffFS::L, luaS_newlstr(), luaV_concat(), BuffFS::pushed, setsvalue2s, and lua_State::top.

Referenced by addstr2buff(), and clearbuff().

◆ tostringbuff()

static int tostringbuff ( TValue * obj,
char * buff )
static

Definition at line 355 of file lua-5.4.3/src/lobject.c.

355 {
356 int len;
358 if (ttisinteger(obj))
359 len = lua_integer2str(buff, MAXNUMBER2STR, ivalue(obj));
360 else {
361 len = lua_number2str(buff, MAXNUMBER2STR, fltvalue(obj));
362 if (buff[strspn(buff, "-0123456789")] == '\0') { /* looks like an int? */
363 buff[len++] = lua_getlocaledecpoint();
364 buff[len++] = '0'; /* adds '.0' to result */
365 }
366 }
367 return len;
368}
#define ttisnumber(o)
#define lua_number2str(s, n)
#define fltvalue(o)
#define lua_integer2str(s, sz, n)

References fltvalue, ivalue, lua_assert, lua_getlocaledecpoint, lua_integer2str, lua_number2str, MAXNUMBER2STR, ttisinteger, and ttisnumber.

Referenced by addnum2buff(), and luaO_tostring().