Coverage Report

Created: 2026-01-25 07:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/testdir/build/lua-master/source/lbaselib.c
Line
Count
Source
1
/*
2
** $Id: lbaselib.c $
3
** Basic library
4
** See Copyright Notice in lua.h
5
*/
6
7
#define lbaselib_c
8
#define LUA_LIB
9
10
#include "lprefix.h"
11
12
13
#include <ctype.h>
14
#include <stdio.h>
15
#include <stdlib.h>
16
#include <string.h>
17
18
#include "lua.h"
19
20
#include "lauxlib.h"
21
#include "lualib.h"
22
#include "llimits.h"
23
24
25
58.9k
static int luaB_print (lua_State *L) {
26
58.9k
  int n = lua_gettop(L);  /* number of arguments */
27
58.9k
  int i;
28
130k
  for (i = 1; i <= n; i++) {  /* for each argument */
29
71.2k
    size_t l;
30
71.2k
    const char *s = luaL_tolstring(L, i, &l);  /* convert it to string */
31
71.2k
    if (i > 1)  /* not the first element? */
32
12.6k
      lua_writestring("\t", 1);  /* add a tab before it */
33
71.2k
    lua_writestring(s, l);  /* print it */
34
71.2k
    lua_pop(L, 1);  /* pop result */
35
71.2k
  }
36
58.9k
  lua_writeline();
37
58.9k
  return 0;
38
58.9k
}
39
40
41
/*
42
** Creates a warning with all given arguments.
43
** Check first for errors; otherwise an error may interrupt
44
** the composition of a warning, leaving it unfinished.
45
*/
46
52.8k
static int luaB_warn (lua_State *L) {
47
52.8k
  int n = lua_gettop(L);  /* number of arguments */
48
52.8k
  int i;
49
52.8k
  luaL_checkstring(L, 1);  /* at least one argument */
50
58.9k
  for (i = 2; i <= n; i++)
51
6.02k
    luaL_checkstring(L, i);  /* make sure all arguments are strings */
52
58.9k
  for (i = 1; i < n; i++)  /* compose warning */
53
6.02k
    lua_warning(L, lua_tostring(L, i), 1);
54
52.8k
  lua_warning(L, lua_tostring(L, n), 0);  /* close warning */
55
52.8k
  return 0;
56
52.8k
}
57
58
59
6.62k
#define SPACECHARS  " \f\n\r\t\v"
60
61
4.61k
static const char *b_str2int (const char *s, unsigned base, lua_Integer *pn) {
62
4.61k
  lua_Unsigned n = 0;
63
4.61k
  int neg = 0;
64
4.61k
  s += strspn(s, SPACECHARS);  /* skip initial spaces */
65
4.61k
  if (*s == '-') { s++; neg = 1; }  /* handle sign */
66
4.33k
  else if (*s == '+') s++;
67
4.61k
  if (!isalnum(cast_uchar(*s)))  /* no digit? */
68
1.65k
    return NULL;
69
23.4k
  do {
70
23.4k
    unsigned digit = cast_uint(isdigit(cast_uchar(*s))
71
23.4k
                               ? *s - '0'
72
23.4k
                               : (toupper(cast_uchar(*s)) - 'A') + 10);
73
23.4k
    if (digit >= base) return NULL;  /* invalid numeral */
74
22.5k
    n = n * base + digit;
75
22.5k
    s++;
76
22.5k
  } while (isalnum(cast_uchar(*s)));
77
2.01k
  s += strspn(s, SPACECHARS);  /* skip trailing spaces */
78
2.01k
  *pn = (lua_Integer)((neg) ? (0u - n) : n);
79
2.01k
  return s;
80
2.96k
}
81
82
83
7.64M
static int luaB_tonumber (lua_State *L) {
84
7.64M
  if (lua_isnoneornil(L, 2)) {  /* standard conversion? */
85
7.64M
    if (lua_type(L, 1) == LUA_TNUMBER) {  /* already a number? */
86
119k
      lua_settop(L, 1);  /* yes; return it */
87
119k
      return 1;
88
119k
    }
89
7.52M
    else {
90
7.52M
      size_t l;
91
7.52M
      const char *s = lua_tolstring(L, 1, &l);
92
7.52M
      if (s != NULL && lua_stringtonumber(L, s) == l + 1)
93
135k
        return 1;  /* successful conversion to number */
94
      /* else not a number */
95
7.38M
      luaL_checkany(L, 1);  /* (but there must be some parameter) */
96
7.38M
    }
97
7.64M
  }
98
5.61k
  else {
99
5.61k
    size_t l;
100
5.61k
    const char *s;
101
5.61k
    lua_Integer n = 0;  /* to avoid warnings */
102
5.61k
    lua_Integer base = luaL_checkinteger(L, 2);
103
5.61k
    luaL_checktype(L, 1, LUA_TSTRING);  /* no numbers as strings */
104
5.61k
    s = lua_tolstring(L, 1, &l);
105
5.61k
    luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range");
106
5.61k
    if (b_str2int(s, cast_uint(base), &n) == s + l) {
107
1.87k
      lua_pushinteger(L, n);
108
1.87k
      return 1;
109
1.87k
    }  /* else not a number */
110
5.61k
  }  /* else not a number */
111
7.39M
  luaL_pushfail(L);  /* not a number */
112
7.39M
  return 1;
113
7.64M
}
114
115
116
28.6k
static int luaB_error (lua_State *L) {
117
28.6k
  int level = (int)luaL_optinteger(L, 2, 1);
118
28.6k
  lua_settop(L, 1);
119
28.6k
  if (lua_type(L, 1) == LUA_TSTRING && level > 0) {
120
25.3k
    luaL_where(L, level);   /* add extra information */
121
25.3k
    lua_pushvalue(L, 1);
122
25.3k
    lua_concat(L, 2);
123
25.3k
  }
124
28.6k
  return lua_error(L);
125
28.6k
}
126
127
128
62.0k
static int luaB_getmetatable (lua_State *L) {
129
62.0k
  luaL_checkany(L, 1);
130
62.0k
  if (!lua_getmetatable(L, 1)) {
131
16.1k
    lua_pushnil(L);
132
16.1k
    return 1;  /* no metatable */
133
16.1k
  }
134
45.9k
  luaL_getmetafield(L, 1, "__metatable");
135
45.9k
  return 1;  /* returns either __metatable field (if present) or metatable */
136
62.0k
}
137
138
139
1.75M
static int luaB_setmetatable (lua_State *L) {
140
1.75M
  int t = lua_type(L, 2);
141
1.75M
  luaL_checktype(L, 1, LUA_TTABLE);
142
1.75M
  luaL_argexpected(L, t == LUA_TNIL || t == LUA_TTABLE, 2, "nil or table");
143
1.75M
  if (l_unlikely(luaL_getmetafield(L, 1, "__metatable") != LUA_TNIL))
144
0
    return luaL_error(L, "cannot change a protected metatable");
145
1.75M
  lua_settop(L, 2);
146
1.75M
  lua_setmetatable(L, 1);
147
1.75M
  return 1;
148
1.75M
}
149
150
151
2.13k
static int luaB_rawequal (lua_State *L) {
152
2.13k
  luaL_checkany(L, 1);
153
2.13k
  luaL_checkany(L, 2);
154
2.13k
  lua_pushboolean(L, lua_rawequal(L, 1, 2));
155
2.13k
  return 1;
156
2.13k
}
157
158
159
2.82k
static int luaB_rawlen (lua_State *L) {
160
2.82k
  int t = lua_type(L, 1);
161
2.82k
  luaL_argexpected(L, t == LUA_TTABLE || t == LUA_TSTRING, 1,
162
2.82k
                      "table or string");
163
2.82k
  lua_pushinteger(L, l_castU2S(lua_rawlen(L, 1)));
164
2.82k
  return 1;
165
2.82k
}
166
167
168
3.60k
static int luaB_rawget (lua_State *L) {
169
3.60k
  luaL_checktype(L, 1, LUA_TTABLE);
170
3.60k
  luaL_checkany(L, 2);
171
3.60k
  lua_settop(L, 2);
172
3.60k
  lua_rawget(L, 1);
173
3.60k
  return 1;
174
3.60k
}
175
176
378k
static int luaB_rawset (lua_State *L) {
177
378k
  luaL_checktype(L, 1, LUA_TTABLE);
178
378k
  luaL_checkany(L, 2);
179
378k
  luaL_checkany(L, 3);
180
378k
  lua_settop(L, 3);
181
378k
  lua_rawset(L, 1);
182
378k
  return 1;
183
378k
}
184
185
186
1.72M
static int pushmode (lua_State *L, int oldmode) {
187
1.72M
  if (oldmode == -1)
188
0
    luaL_pushfail(L);  /* invalid call to 'lua_gc' */
189
1.72M
  else
190
1.72M
    lua_pushstring(L, (oldmode == LUA_GCINC) ? "incremental"
191
1.72M
                                             : "generational");
192
1.72M
  return 1;
193
1.72M
}
194
195
196
/*
197
** check whether call to 'lua_gc' was valid (not inside a finalizer)
198
*/
199
253k
#define checkvalres(res) { if (res == -1) break; }
200
201
2.06M
static int luaB_collectgarbage (lua_State *L) {
202
2.06M
  static const char *const opts[] = {"stop", "restart", "collect",
203
2.06M
    "count", "step", "isrunning", "generational", "incremental",
204
2.06M
    "param", NULL};
205
2.06M
  static const char optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT,
206
2.06M
    LUA_GCCOUNT, LUA_GCSTEP, LUA_GCISRUNNING, LUA_GCGEN, LUA_GCINC,
207
2.06M
    LUA_GCPARAM};
208
2.06M
  int o = optsnum[luaL_checkoption(L, 1, "collect", opts)];
209
2.06M
  switch (o) {
210
573
    case LUA_GCCOUNT: {
211
573
      int k = lua_gc(L, o);
212
573
      int b = lua_gc(L, LUA_GCCOUNTB);
213
573
      checkvalres(k);
214
573
      lua_pushnumber(L, (lua_Number)k + ((lua_Number)b/1024));
215
573
      return 1;
216
573
    }
217
4.51k
    case LUA_GCSTEP: {
218
4.51k
      lua_Integer n = luaL_optinteger(L, 2, 0);
219
4.51k
      int res = lua_gc(L, o, cast_sizet(n));
220
4.51k
      checkvalres(res);
221
4.51k
      lua_pushboolean(L, res);
222
4.51k
      return 1;
223
4.51k
    }
224
1.93k
    case LUA_GCISRUNNING: {
225
1.93k
      int res = lua_gc(L, o);
226
1.93k
      checkvalres(res);
227
1.93k
      lua_pushboolean(L, res);
228
1.93k
      return 1;
229
1.93k
    }
230
1.72M
    case LUA_GCGEN: {
231
1.72M
      return pushmode(L, lua_gc(L, o));
232
1.93k
    }
233
5.63k
    case LUA_GCINC: {
234
5.63k
      return pushmode(L, lua_gc(L, o));
235
1.93k
    }
236
0
    case LUA_GCPARAM: {
237
0
      static const char *const params[] = {
238
0
        "minormul", "majorminor", "minormajor",
239
0
        "pause", "stepmul", "stepsize", NULL};
240
0
      static const char pnum[] = {
241
0
        LUA_GCPMINORMUL, LUA_GCPMAJORMINOR, LUA_GCPMINORMAJOR,
242
0
        LUA_GCPPAUSE, LUA_GCPSTEPMUL, LUA_GCPSTEPSIZE};
243
0
      int p = pnum[luaL_checkoption(L, 2, NULL, params)];
244
0
      lua_Integer value = luaL_optinteger(L, 3, -1);
245
0
      lua_pushinteger(L, lua_gc(L, o, p, (int)value));
246
0
      return 1;
247
1.93k
    }
248
246k
    default: {
249
246k
      int res = lua_gc(L, o);
250
246k
      checkvalres(res);
251
246k
      lua_pushinteger(L, res);
252
246k
      return 1;
253
246k
    }
254
2.06M
  }
255
0
  luaL_pushfail(L);  /* invalid call (inside a finalizer) */
256
0
  return 1;
257
2.06M
}
258
259
260
15.4M
static int luaB_type (lua_State *L) {
261
15.4M
  int t = lua_type(L, 1);
262
15.4M
  luaL_argcheck(L, t != LUA_TNONE, 1, "value expected");
263
15.4M
  lua_pushstring(L, lua_typename(L, t));
264
15.4M
  return 1;
265
15.4M
}
266
267
268
119k
static int luaB_next (lua_State *L) {
269
119k
  luaL_checktype(L, 1, LUA_TTABLE);
270
119k
  lua_settop(L, 2);  /* create a 2nd argument if there isn't one */
271
119k
  if (lua_next(L, 1))
272
23.3k
    return 2;
273
96.0k
  else {
274
96.0k
    lua_pushnil(L);
275
96.0k
    return 1;
276
96.0k
  }
277
119k
}
278
279
280
0
static int pairscont (lua_State *L, int status, lua_KContext k) {
281
0
  (void)L; (void)status; (void)k;  /* unused */
282
0
  return 4;  /* __pairs did all the work, just return its results */
283
0
}
284
285
90.5k
static int luaB_pairs (lua_State *L) {
286
90.5k
  luaL_checkany(L, 1);
287
90.5k
  if (luaL_getmetafield(L, 1, "__pairs") == LUA_TNIL) {  /* no metamethod? */
288
90.5k
    lua_pushcfunction(L, luaB_next);  /* will return generator and */
289
90.5k
    lua_pushvalue(L, 1);  /* state */
290
90.5k
    lua_pushnil(L);  /* initial value */
291
90.5k
    lua_pushnil(L);  /* to-be-closed object */
292
90.5k
  }
293
9
  else {
294
9
    lua_pushvalue(L, 1);  /* argument 'self' to metamethod */
295
9
    lua_callk(L, 1, 4, 0, pairscont);  /* get 4 values from metamethod */
296
9
  }
297
90.5k
  return 4;
298
90.5k
}
299
300
301
/*
302
** Traversal function for 'ipairs'
303
*/
304
14.4k
static int ipairsaux (lua_State *L) {
305
14.4k
  lua_Integer i = luaL_checkinteger(L, 2);
306
14.4k
  i = luaL_intop(+, i, 1);
307
14.4k
  lua_pushinteger(L, i);
308
14.4k
  return (lua_geti(L, 1, i) == LUA_TNIL) ? 1 : 2;
309
14.4k
}
310
311
312
/*
313
** 'ipairs' function. Returns 'ipairsaux', given "table", 0.
314
** (The given "table" may not be a table.)
315
*/
316
11.4k
static int luaB_ipairs (lua_State *L) {
317
11.4k
  luaL_checkany(L, 1);
318
11.4k
  lua_pushcfunction(L, ipairsaux);  /* iteration function */
319
11.4k
  lua_pushvalue(L, 1);  /* state */
320
11.4k
  lua_pushinteger(L, 0);  /* initial value */
321
11.4k
  return 3;
322
11.4k
}
323
324
325
4.35M
static int load_aux (lua_State *L, int status, int envidx) {
326
4.35M
  if (l_likely(status == LUA_OK)) {
327
822k
    if (envidx != 0) {  /* 'env' parameter? */
328
1.62k
      lua_pushvalue(L, envidx);  /* environment for loaded function */
329
1.62k
      if (!lua_setupvalue(L, -2, 1))  /* set it as 1st upvalue */
330
10
        lua_pop(L, 1);  /* remove 'env' if not used by previous call */
331
1.62k
    }
332
822k
    return 1;
333
822k
  }
334
3.53M
  else {  /* error (message is on top of the stack) */
335
3.53M
    luaL_pushfail(L);
336
3.53M
    lua_insert(L, -2);  /* put before error message */
337
3.53M
    return 2;  /* return fail plus error message */
338
3.53M
  }
339
4.35M
}
340
341
342
4.42M
static const char *getMode (lua_State *L, int idx) {
343
4.42M
  const char *mode = luaL_optstring(L, idx, "bt");
344
4.42M
  if (strchr(mode, 'B') != NULL)  /* Lua code cannot use fixed buffers */
345
1
    luaL_argerror(L, idx, "invalid mode");
346
4.42M
  return mode;
347
4.42M
}
348
349
350
8.66k
static int luaB_loadfile (lua_State *L) {
351
8.66k
  const char *fname = luaL_optstring(L, 1, NULL);
352
8.66k
  const char *mode = getMode(L, 2);
353
8.66k
  int env = (!lua_isnone(L, 3) ? 3 : 0);  /* 'env' index or 0 if no 'env' */
354
8.66k
  int status = luaL_loadfilex(L, fname, mode);
355
8.66k
  return load_aux(L, status, env);
356
8.66k
}
357
358
359
/*
360
** {======================================================
361
** Generic Read function
362
** =======================================================
363
*/
364
365
366
/*
367
** reserved slot, above all arguments, to hold a copy of the returned
368
** string to avoid it being collected while parsed. 'load' has four
369
** optional arguments (chunk, source name, mode, and environment).
370
*/
371
1.77M
#define RESERVEDSLOT  5
372
373
374
/*
375
** Reader for generic 'load' function: 'lua_load' uses the
376
** stack for internal stuff, so the reader cannot change the
377
** stack top. Instead, it keeps its resulting string in a
378
** reserved slot inside the stack.
379
*/
380
1.09M
static const char *generic_reader (lua_State *L, void *ud, size_t *size) {
381
1.09M
  (void)(ud);  /* not used */
382
1.09M
  luaL_checkstack(L, 2, "too many nested functions");
383
1.09M
  lua_pushvalue(L, 1);  /* get function */
384
1.09M
  lua_call(L, 0, 1);  /* call it */
385
1.09M
  if (lua_isnil(L, -1)) {
386
486k
    lua_pop(L, 1);  /* pop result */
387
486k
    *size = 0;
388
486k
    return NULL;
389
486k
  }
390
610k
  else if (l_unlikely(!lua_isstring(L, -1)))
391
336
    luaL_error(L, "reader function must return a string");
392
610k
  lua_replace(L, RESERVEDSLOT);  /* save string in reserved slot */
393
610k
  return lua_tolstring(L, RESERVEDSLOT, size);
394
1.09M
}
395
396
397
4.42M
static int luaB_load (lua_State *L) {
398
4.42M
  int status;
399
4.42M
  size_t l;
400
4.42M
  const char *s = lua_tolstring(L, 1, &l);
401
4.42M
  const char *mode = getMode(L, 3);
402
4.42M
  int env = (!lua_isnone(L, 4) ? 4 : 0);  /* 'env' index or 0 if no 'env' */
403
4.42M
  if (s != NULL) {  /* loading a string? */
404
3.25M
    const char *chunkname = luaL_optstring(L, 2, s);
405
3.25M
    status = luaL_loadbufferx(L, s, l, chunkname, mode);
406
3.25M
  }
407
1.16M
  else {  /* loading from a reader function */
408
1.16M
    const char *chunkname = luaL_optstring(L, 2, "=(load)");
409
1.16M
    luaL_checktype(L, 1, LUA_TFUNCTION);
410
1.16M
    lua_settop(L, RESERVEDSLOT);  /* create reserved slot */
411
1.16M
    status = lua_load(L, generic_reader, NULL, chunkname, mode);
412
1.16M
  }
413
4.42M
  return load_aux(L, status, env);
414
4.42M
}
415
416
/* }====================================================== */
417
418
419
24.6k
static int dofilecont (lua_State *L, int d1, lua_KContext d2) {
420
24.6k
  (void)d1;  (void)d2;  /* only to match 'lua_Kfunction' prototype */
421
24.6k
  return lua_gettop(L) - 1;
422
24.6k
}
423
424
425
24.7k
static int luaB_dofile (lua_State *L) {
426
24.7k
  const char *fname = luaL_optstring(L, 1, NULL);
427
24.7k
  lua_settop(L, 1);
428
24.7k
  if (l_unlikely(luaL_loadfile(L, fname) != LUA_OK))
429
46
    return lua_error(L);
430
24.6k
  lua_callk(L, 0, LUA_MULTRET, 0, dofilecont);
431
24.6k
  return dofilecont(L, 0, 0);
432
24.7k
}
433
434
435
391k
static int luaB_assert (lua_State *L) {
436
391k
  if (l_likely(lua_toboolean(L, 1)))  /* condition is true? */
437
368k
    return lua_gettop(L);  /* return all arguments */
438
23.8k
  else {  /* error */
439
23.8k
    luaL_checkany(L, 1);  /* there must be a condition */
440
23.8k
    lua_remove(L, 1);  /* remove it */
441
23.8k
    lua_pushliteral(L, "assertion failed!");  /* default message */
442
23.8k
    lua_settop(L, 1);  /* leave only message (default if no other one) */
443
23.8k
    return luaB_error(L);  /* call 'error' */
444
23.8k
  }
445
391k
}
446
447
448
86.7k
static int luaB_select (lua_State *L) {
449
86.7k
  int n = lua_gettop(L);
450
86.7k
  if (lua_type(L, 1) == LUA_TSTRING && *lua_tostring(L, 1) == '#') {
451
25.2k
    lua_pushinteger(L, n-1);
452
25.2k
    return 1;
453
25.2k
  }
454
61.4k
  else {
455
61.4k
    lua_Integer i = luaL_checkinteger(L, 1);
456
61.4k
    if (i < 0) i = n + i;
457
61.2k
    else if (i > n) i = n;
458
61.4k
    luaL_argcheck(L, 1 <= i, 1, "index out of range");
459
61.4k
    return n - (int)i;
460
61.4k
  }
461
86.7k
}
462
463
464
/*
465
** Continuation function for 'pcall' and 'xpcall'. Both functions
466
** already pushed a 'true' before doing the call, so in case of success
467
** 'finishpcall' only has to return everything in the stack minus
468
** 'extra' values (where 'extra' is exactly the number of items to be
469
** ignored).
470
*/
471
301k
static int finishpcall (lua_State *L, int status, lua_KContext extra) {
472
301k
  if (l_unlikely(status != LUA_OK && status != LUA_YIELD)) {  /* error? */
473
242k
    lua_pushboolean(L, 0);  /* first result (false) */
474
242k
    lua_pushvalue(L, -2);  /* error message */
475
242k
    return 2;  /* return false, msg */
476
242k
  }
477
58.9k
  else
478
58.9k
    return lua_gettop(L) - (int)extra;  /* return all results */
479
301k
}
480
481
482
248k
static int luaB_pcall (lua_State *L) {
483
248k
  int status;
484
248k
  luaL_checkany(L, 1);
485
248k
  lua_pushboolean(L, 1);  /* first result if no errors */
486
248k
  lua_insert(L, 1);  /* put it in place */
487
248k
  status = lua_pcallk(L, lua_gettop(L) - 2, LUA_MULTRET, 0, 0, finishpcall);
488
248k
  return finishpcall(L, status, 0);
489
248k
}
490
491
492
/*
493
** Do a protected call with error handling. After 'lua_rotate', the
494
** stack will have <f, err, true, f, [args...]>; so, the function passes
495
** 2 to 'finishpcall' to skip the 2 first values when returning results.
496
*/
497
606k
static int luaB_xpcall (lua_State *L) {
498
606k
  int status;
499
606k
  int n = lua_gettop(L);
500
606k
  luaL_checktype(L, 2, LUA_TFUNCTION);  /* check error function */
501
606k
  lua_pushboolean(L, 1);  /* first result */
502
606k
  lua_pushvalue(L, 1);  /* function */
503
606k
  lua_rotate(L, 3, 2);  /* move them below function's arguments */
504
606k
  status = lua_pcallk(L, n - 2, LUA_MULTRET, 2, 2, finishpcall);
505
606k
  return finishpcall(L, status, 2);
506
606k
}
507
508
509
1.41M
static int luaB_tostring (lua_State *L) {
510
1.41M
  luaL_checkany(L, 1);
511
1.41M
  luaL_tolstring(L, 1, NULL);
512
1.41M
  return 1;
513
1.41M
}
514
515
516
static const luaL_Reg base_funcs[] = {
517
  {"assert", luaB_assert},
518
  {"collectgarbage", luaB_collectgarbage},
519
  {"dofile", luaB_dofile},
520
  {"error", luaB_error},
521
  {"getmetatable", luaB_getmetatable},
522
  {"ipairs", luaB_ipairs},
523
  {"loadfile", luaB_loadfile},
524
  {"load", luaB_load},
525
  {"next", luaB_next},
526
  {"pairs", luaB_pairs},
527
  {"pcall", luaB_pcall},
528
  {"print", luaB_print},
529
  {"warn", luaB_warn},
530
  {"rawequal", luaB_rawequal},
531
  {"rawlen", luaB_rawlen},
532
  {"rawget", luaB_rawget},
533
  {"rawset", luaB_rawset},
534
  {"select", luaB_select},
535
  {"setmetatable", luaB_setmetatable},
536
  {"tonumber", luaB_tonumber},
537
  {"tostring", luaB_tostring},
538
  {"type", luaB_type},
539
  {"xpcall", luaB_xpcall},
540
  /* placeholders */
541
  {LUA_GNAME, NULL},
542
  {"_VERSION", NULL},
543
  {NULL, NULL}
544
};
545
546
547
9.15k
LUAMOD_API int luaopen_base (lua_State *L) {
548
  /* open lib into global table */
549
9.15k
  lua_pushglobaltable(L);
550
9.15k
  luaL_setfuncs(L, base_funcs, 0);
551
  /* set global _G */
552
9.15k
  lua_pushvalue(L, -1);
553
9.15k
  lua_setfield(L, -2, LUA_GNAME);
554
  /* set global _VERSION */
555
9.15k
  lua_pushliteral(L, LUA_VERSION);
556
9.15k
  lua_setfield(L, -2, "_VERSION");
557
9.15k
  return 1;
558
9.15k
}
559