Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
lobject.c File Reference
#include <ctype.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "lua.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.

Macros

#define lobject_c
 
#define LUA_CORE
 

Functions

int luaO_int2fb (unsigned int x)
 
int luaO_fb2int (int x)
 
int luaO_log2 (unsigned int x)
 
int luaO_rawequalObj (const TValue *t1, const TValue *t2)
 
int luaO_str2d (const char *s, lua_Number *result)
 
static void pushstr (lua_State *L, const char *str)
 
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 bufflen)
 

Variables

const TValue luaO_nilobject_ = {{NULL}, LUA_TNIL}
 

Macro Definition Documentation

◆ lobject_c

#define lobject_c

Definition at line 13 of file lua-5.1.5/src/lobject.c.

◆ LUA_CORE

#define LUA_CORE

Definition at line 14 of file lua-5.1.5/src/lobject.c.

Function Documentation

◆ luaO_chunkid()

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

Definition at line 182 of file lua-5.1.5/src/lobject.c.

182 {
183 if (*source == '=') {
184 strncpy(out, source+1, bufflen); /* remove first char */
185 out[bufflen-1] = '\0'; /* ensures null termination */
186 }
187 else { /* out = "source", or "...source" */
188 if (*source == '@') {
189 size_t l;
190 source++; /* skip the `@' */
191 bufflen -= sizeof(" '...' ");
192 l = strlen(source);
193 strcpy(out, "");
194 if (l > bufflen) {
195 source += (l-bufflen); /* get last part of file name */
196 strcat(out, "...");
197 }
198 strcat(out, source);
199 }
200 else { /* out = [string "string"] */
201 size_t len = strcspn(source, "\n\r"); /* stop at first newline */
202 bufflen -= sizeof(" [string \"...\"] ");
203 if (len > bufflen) len = bufflen;
204 strcpy(out, "[string \"");
205 if (source[len] != '\0') { /* must truncate? */
206 strncat(out, source, len);
207 strcat(out, "...");
208 }
209 else
210 strcat(out, source);
211 strcat(out, "\"]");
212 }
213 }
214}
#define bufflen(B)

References bufflen.

Referenced by addinfo(), addinfo(), funcinfo(), funcinfo(), funcinfo(), funcinfo(), info_tailcall(), lexerror(), luaG_addinfo(), and luaX_lexerror().

◆ luaO_fb2int()

int luaO_fb2int ( int x)

Definition at line 47 of file lua-5.1.5/src/lobject.c.

47 {
48 int e = (x >> 3) & 31;
49 if (e == 0) return x;
50 else return ((x & 7)+8) << (e - 1);
51}

Referenced by luaV_execute(), and luaV_execute().

◆ luaO_int2fb()

int luaO_int2fb ( unsigned int x)

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

35 {
36 int e = 0; /* expoent */
37 while (x >= 16) {
38 x = (x+1) >> 1;
39 e++;
40 }
41 if (x < 8) return x;
42 else return ((e+1) << 3) | (cast_int(x) - 8);
43}
#define cast_int(i)

References cast_int.

Referenced by constructor(), constructor(), and constructor().

◆ luaO_log2()

int luaO_log2 ( unsigned int x)

Definition at line 54 of file lua-5.1.5/src/lobject.c.

54 {
55 static const lu_byte log_2[256] = {
56 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,
57 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,
58 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,
59 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,
60 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,
61 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,
62 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,
63 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
64 };
65 int l = -1;
66 while (x >= 256) { l += 8; x >>= 8; }
67 return l + log_2[x];
68
69}
unsigned char lu_byte

◆ luaO_pushfstring()

◆ luaO_pushvfstring()

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

Definition at line 111 of file lua-5.1.5/src/lobject.c.

111 {
112 int n = 1;
113 pushstr(L, "");
114 for (;;) {
115 const char *e = strchr(fmt, '%');
116 if (e == NULL) break;
117 setsvalue2s(L, L->top, luaS_newlstr(L, fmt, e-fmt));
118 incr_top(L);
119 switch (*(e+1)) {
120 case 's': {
121 const char *s = va_arg(argp, char *);
122 if (s == NULL) s = "(null)";
123 pushstr(L, s);
124 break;
125 }
126 case 'c': {
127 char buff[2];
128 buff[0] = cast(char, va_arg(argp, int));
129 buff[1] = '\0';
130 pushstr(L, buff);
131 break;
132 }
133 case 'd': {
134 setnvalue(L->top, cast_num(va_arg(argp, int)));
135 incr_top(L);
136 break;
137 }
138 case 'f': {
139 setnvalue(L->top, cast_num(va_arg(argp, l_uacNumber)));
140 incr_top(L);
141 break;
142 }
143 case 'p': {
144 char buff[4*sizeof(void *) + 8]; /* should be enough space for a `%p' */
145 sprintf(buff, "%p", va_arg(argp, void *));
146 pushstr(L, buff);
147 break;
148 }
149 case '%': {
150 pushstr(L, "%");
151 break;
152 }
153 default: {
154 char buff[3];
155 buff[0] = '%';
156 buff[1] = *(e+1);
157 buff[2] = '\0';
158 pushstr(L, buff);
159 break;
160 }
161 }
162 n += 2;
163 fmt = e+2;
164 }
165 pushstr(L, fmt);
166 luaV_concat(L, n+1, cast_int(L->top - L->base) - 1);
167 L->top -= n;
168 return svalue(L->top - 1);
169}
#define NULL
Definition gmacros.h:924
#define incr_top(L)
LUAI_UACNUMBER l_uacNumber
#define cast_num(i)
#define cast(t, exp)
static void pushstr(lua_State *L, const char *str)
#define setsvalue2s
#define setnvalue(obj, x)
#define svalue(o)
TString * luaS_newlstr(lua_State *L, const char *str, size_t l)
void luaV_concat(lua_State *L, int total, int last)
CURL_EXTERN CURLMcode curl_socket_t s
Definition multi.h:318

References lua_State::base, cast, cast_int, cast_num, incr_top, luaS_newlstr(), luaV_concat(), NULL, pushstr(), s, setnvalue, setsvalue2s, svalue, and lua_State::top.

Referenced by lua_pushfstring(), lua_pushvfstring(), luaG_runerror(), and luaO_pushfstring().

◆ luaO_rawequalObj()

int luaO_rawequalObj ( const TValue * t1,
const TValue * t2 )

Definition at line 72 of file lua-5.1.5/src/lobject.c.

72 {
73 if (ttype(t1) != ttype(t2)) return 0;
74 else switch (ttype(t1)) {
75 case LUA_TNIL:
76 return 1;
77 case LUA_TNUMBER:
78 return luai_numeq(nvalue(t1), nvalue(t2));
79 case LUA_TBOOLEAN:
80 return bvalue(t1) == bvalue(t2); /* boolean true must be 1 !! */
82 return pvalue(t1) == pvalue(t2);
83 default:
85 return gcvalue(t1) == gcvalue(t2);
86 }
87}
#define lua_assert(c)
#define gcvalue(o)
#define pvalue(o)
#define nvalue(o)
#define iscollectable(o)
#define bvalue(o)
#define ttype(o)
#define LUA_TBOOLEAN
#define LUA_TNUMBER
#define LUA_TLIGHTUSERDATA
#define LUA_TNIL
#define luai_numeq(a, b)

References bvalue, gcvalue, iscollectable, lua_assert, LUA_TBOOLEAN, LUA_TLIGHTUSERDATA, LUA_TNIL, LUA_TNUMBER, luai_numeq, nvalue, pvalue, and ttype.

Referenced by addk(), call_orderTM(), findindex(), get_compTM(), lua_rawequal(), and luaH_get().

◆ luaO_str2d()

int luaO_str2d ( const char * s,
lua_Number * result )

Definition at line 90 of file lua-5.1.5/src/lobject.c.

90 {
91 char *endptr;
92 *result = lua_str2number(s, &endptr);
93 if (endptr == s) return 0; /* conversion failed */
94 if (*endptr == 'x' || *endptr == 'X') /* maybe an hexadecimal constant? */
95 *result = cast_num(strtoul(s, &endptr, 16));
96 if (*endptr == '\0') return 1; /* most common case */
97 while (isspace(cast(unsigned char, *endptr))) endptr++;
98 if (*endptr != '\0') return 0; /* invalid trailing characters? */
99 return 1;
100}
#define lua_str2number(s, p)

References cast, cast_num, lua_str2number, and s.

Referenced by luaV_tonumber(), read_numeral(), and trydecpoint().

◆ pushstr()

static void pushstr ( lua_State * L,
const char * str )
static

Definition at line 104 of file lua-5.1.5/src/lobject.c.

104 {
105 setsvalue2s(L, L->top, luaS_new(L, str));
106 incr_top(L);
107}
#define luaS_new(L, s)

References incr_top, luaS_new, setsvalue2s, and lua_State::top.

Referenced by luaO_pushvfstring().

Variable Documentation

◆ luaO_nilobject_

const TValue luaO_nilobject_ = {{NULL}, LUA_TNIL}

Definition at line 27 of file lua-5.1.5/src/lobject.c.

27{{NULL}, LUA_TNIL};