• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tarantool / luajit / 13940950676

19 Mar 2025 07:17AM UTC coverage: 93.013% (+0.05%) from 92.966%
13940950676

push

github

Buristan
ci: disable integration-tarantool-ecosystem.yml

This patch prevents runs of the aforementioned workflow until the
corresponding workflow in the Tarantool is fixed.

Relates to tarantool/tarantool#11220

5702 of 6038 branches covered (94.44%)

Branch coverage included in aggregate %.

21723 of 23447 relevant lines covered (92.65%)

2959970.97 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.0
/src/luajit.c
1
/*
2
** LuaJIT frontend. Runs commands, scripts, read-eval-print (REPL) etc.
3
** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
4
**
5
** Major portions taken verbatim or adapted from the Lua interpreter.
6
** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h
7
*/
8

9
#include <stdio.h>
10
#include <stdlib.h>
11
#include <string.h>
12

13
#define luajit_c
14

15
#include "lua.h"
16
#include "lauxlib.h"
17
#include "lualib.h"
18
#include "luajit.h"
19

20
#include "lj_arch.h"
21

22
#if LJ_TARGET_POSIX
23
#include <unistd.h>
24
#define lua_stdin_is_tty()        isatty(0)
25
#elif LJ_TARGET_WINDOWS
26
#include <io.h>
27
#ifdef __BORLANDC__
28
#define lua_stdin_is_tty()        isatty(_fileno(stdin))
29
#else
30
#define lua_stdin_is_tty()        _isatty(_fileno(stdin))
31
#endif
32
#else
33
#define lua_stdin_is_tty()        1
34
#endif
35

36
#if !LJ_TARGET_CONSOLE
37
#include <signal.h>
38
#endif
39

40
static lua_State *globalL = NULL;
41
static const char *progname = LUA_PROGNAME;
42
static char *empty_argv[2] = { NULL, NULL };
43

44
#if !LJ_TARGET_CONSOLE
45
static void lstop(lua_State *L, lua_Debug *ar)
×
46
{
47
  (void)ar;  /* unused arg. */
×
48
  lua_sethook(L, NULL, 0, 0);
×
49
  /* Avoid luaL_error -- a C hook doesn't add an extra frame. */
50
  luaL_where(L, 0);
×
51
  lua_pushfstring(L, "%sinterrupted!", lua_tostring(L, -1));
×
52
  lua_error(L);
×
53
}
×
54

55
static void laction(int i)
×
56
{
57
  signal(i, SIG_DFL); /* if another SIGINT happens before lstop,
×
58
                         terminate process (default action) */
59
  lua_sethook(globalL, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1);
×
60
}
×
61
#endif
62

63
static void print_usage(void)
5✔
64
{
65
  fputs("usage: ", stderr);
5✔
66
  fputs(progname, stderr);
5✔
67
  fputs(" [options]... [script [args]...].\n"
5✔
68
  "Available options are:\n"
69
  "  -e chunk  Execute string " LUA_QL("chunk") ".\n"
70
  "  -l name   Require library " LUA_QL("name") ".\n"
71
  "  -b ...    Save or list bytecode.\n"
72
  "  -j cmd    Perform LuaJIT control command.\n"
73
  "  -O[opt]   Control LuaJIT optimizations.\n"
74
  "  -i        Enter interactive mode after executing " LUA_QL("script") ".\n"
75
  "  -v        Show version information.\n"
76
  "  -t<cmd>   Execute tool.\n"
77
  "  -E        Ignore environment variables.\n"
78
  "  --        Stop handling options.\n"
79
  "  -         Execute stdin and stop handling options.\n", stderr);
80
  fflush(stderr);
5✔
81
}
5✔
82

83
static void print_tools_usage(void)
2✔
84
{
85
  fputs("usage: ", stderr);
2✔
86
  fputs(progname, stderr);
2✔
87
  fputs(" -t<cmd>\n"
2✔
88
  "Available tools are:\n"
89
  "  -m [--leak-only] input  Memprof profile data parser.\n"
90
  "  -s input                Sysprof profile data parser.\n", stderr);
91
  fflush(stderr);
2✔
92
}
2✔
93

94
static void l_message(const char *msg)
7✔
95
{
96
  if (progname) { fputs(progname, stderr); fputc(':', stderr); fputc(' ', stderr); }
7✔
97
  fputs(msg, stderr); fputc('\n', stderr);
7✔
98
  fflush(stderr);
7✔
99
}
7✔
100

101
static int report(lua_State *L, int status)
651✔
102
{
103
  if (status && !lua_isnil(L, -1)) {
651✔
104
    const char *msg = lua_tostring(L, -1);
6✔
105
    if (msg == NULL) msg = "(error object is not a string)";
6✔
106
    l_message(msg);
6✔
107
    lua_pop(L, 1);
6✔
108
  }
109
  return status;
651✔
110
}
111

112
static int traceback(lua_State *L)
4✔
113
{
114
  if (!lua_isstring(L, 1)) { /* Non-string error object? Try metamethod. */
4✔
115
    if (lua_isnoneornil(L, 1) ||
2✔
116
        !luaL_callmeta(L, 1, "__tostring") ||
1✔
117
        !lua_isstring(L, -1))
×
118
      return 1;  /* Return non-string error object. */
1✔
119
    lua_remove(L, 1);  /* Replace object by result of __tostring metamethod. */
×
120
  }
121
  luaL_traceback(L, L, lua_tostring(L, 1), 1);
3✔
122
  return 1;
3✔
123
}
124

125
static int docall(lua_State *L, int narg, int clear)
677✔
126
{
127
  int status;
677✔
128
  int base = lua_gettop(L) - narg;  /* function index */
677✔
129
  lua_pushcfunction(L, traceback);  /* push traceback function */
677✔
130
  lua_insert(L, base);  /* put it under chunk and args */
677✔
131
#if !LJ_TARGET_CONSOLE
132
  signal(SIGINT, laction);
677✔
133
#endif
134
  status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base);
983✔
135
#if !LJ_TARGET_CONSOLE
136
  signal(SIGINT, SIG_DFL);
477✔
137
#endif
138
  lua_remove(L, base);  /* remove traceback function */
477✔
139
  /* force a complete garbage collection in case of errors */
140
  if (status != LUA_OK) lua_gc(L, LUA_GCCOLLECT, 0);
477✔
141
  return status;
477✔
142
}
143

144
static void print_version(void)
8✔
145
{
146
  fputs(LUAJIT_VERSION " -- " LUAJIT_COPYRIGHT ". " LUAJIT_URL "\n", stdout);
8✔
147
}
8✔
148

149
static void print_jit_status(lua_State *L)
4✔
150
{
151
  int n;
4✔
152
  const char *s;
4✔
153
  lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
4✔
154
  lua_getfield(L, -1, "jit");  /* Get jit.* module table. */
4✔
155
  lua_remove(L, -2);
4✔
156
  lua_getfield(L, -1, "status");
4✔
157
  lua_remove(L, -2);
4✔
158
  n = lua_gettop(L);
4✔
159
  lua_call(L, 0, LUA_MULTRET);
4✔
160
  fputs(lua_toboolean(L, n) ? "JIT: ON" : "JIT: OFF", stdout);
4✔
161
  for (n++; (s = lua_tostring(L, n)); n++) {
56✔
162
    putc(' ', stdout);
52✔
163
    fputs(s, stdout);
52✔
164
  }
165
  putc('\n', stdout);
4✔
166
  lua_settop(L, 0);  /* clear stack */
4✔
167
}
4✔
168

169
static void createargtable(lua_State *L, char **argv, int argc, int argf)
358✔
170
{
171
  int i;
358✔
172
  lua_createtable(L, argc - argf, argf);
358✔
173
  for (i = 0; i < argc; i++) {
2,285✔
174
    lua_pushstring(L, argv[i]);
1,569✔
175
    lua_rawseti(L, -2, i - argf);
1,569✔
176
  }
177
  lua_setglobal(L, "arg");
358✔
178
}
358✔
179

180
static int dofile(lua_State *L, const char *name)
1✔
181
{
182
  int status = luaL_loadfile(L, name) || docall(L, 0, 1);
1✔
183
  return report(L, status);
1✔
184
}
185

186
static int dostring(lua_State *L, const char *s, const char *name)
315✔
187
{
188
  int status = luaL_loadbuffer(L, s, strlen(s), name) || docall(L, 0, 1);
315✔
189
  return report(L, status);
312✔
190
}
191

192
static int dolibrary(lua_State *L, const char *name)
57✔
193
{
194
  lua_getglobal(L, "require");
57✔
195
  lua_pushstring(L, name);
57✔
196
  return report(L, docall(L, 1, 1));
57✔
197
}
198

199
static void write_prompt(lua_State *L, int firstline)
131✔
200
{
201
  const char *p;
131✔
202
  lua_getfield(L, LUA_GLOBALSINDEX, firstline ? "_PROMPT" : "_PROMPT2");
240✔
203
  p = lua_tostring(L, -1);
131✔
204
  if (p == NULL) p = firstline ? LUA_PROMPT : LUA_PROMPT2;
131✔
205
  fputs(p, stdout);
131✔
206
  fflush(stdout);
131✔
207
  lua_pop(L, 1);  /* remove global */
131✔
208
}
131✔
209

210
static int incomplete(lua_State *L, int status)
127✔
211
{
212
  if (status == LUA_ERRSYNTAX) {
127✔
213
    size_t lmsg;
109✔
214
    const char *msg = lua_tolstring(L, -1, &lmsg);
109✔
215
    const char *tp = msg + lmsg - (sizeof(LUA_QL("<eof>")) - 1);
109✔
216
    if (strstr(msg, LUA_QL("<eof>")) == tp) {
109✔
217
      lua_pop(L, 1);
109✔
218
      return 1;
109✔
219
    }
220
  }
221
  return 0;  /* else... */
222
}
223

224
static int pushline(lua_State *L, int firstline)
131✔
225
{
226
  char buf[LUA_MAXINPUT];
131✔
227
  write_prompt(L, firstline);
131✔
228
  if (fgets(buf, LUA_MAXINPUT, stdin)) {
131✔
229
    size_t len = strlen(buf);
127✔
230
    if (len > 0 && buf[len-1] == '\n')
127✔
231
      buf[len-1] = '\0';
125✔
232
    if (firstline && buf[0] == '=')
127✔
233
      lua_pushfstring(L, "return %s", buf+1);
5✔
234
    else
235
      lua_pushstring(L, buf);
122✔
236
    return 1;
127✔
237
  }
238
  return 0;
239
}
240

241
static int loadline(lua_State *L)
22✔
242
{
243
  int status;
22✔
244
  lua_settop(L, 0);
22✔
245
  if (!pushline(L, 1))
22✔
246
    return -1;  /* no input */
247
  for (;;) {  /* repeat until gets a complete line */
236✔
248
    status = luaL_loadbuffer(L, lua_tostring(L, 1), lua_strlen(L, 1), "=stdin");
127✔
249
    if (!incomplete(L, status)) break;  /* cannot try to add lines? */
127✔
250
    if (!pushline(L, 0))  /* no more input? */
109✔
251
      return -1;
252
    lua_pushliteral(L, "\n");  /* add a new line... */
109✔
253
    lua_insert(L, -2);  /* ...between the two lines */
109✔
254
    lua_concat(L, 3);  /* join them */
109✔
255
  }
256
  lua_remove(L, 1);  /* remove line */
18✔
257
  return status;
18✔
258
}
259

260
static void dotty(lua_State *L)
4✔
261
{
262
  int status;
4✔
263
  const char *oldprogname = progname;
4✔
264
  progname = NULL;
4✔
265
  while ((status = loadline(L)) != -1) {
26✔
266
    if (status == LUA_OK) status = docall(L, 0, 0);
18✔
267
    report(L, status);
18✔
268
    if (status == LUA_OK && lua_gettop(L) > 0) {  /* any result to print? */
18✔
269
      lua_getglobal(L, "print");
5✔
270
      lua_insert(L, 1);
5✔
271
      if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != 0)
5✔
272
        l_message(lua_pushfstring(L, "error calling " LUA_QL("print") " (%s)",
×
273
                                  lua_tostring(L, -1)));
274
    }
275
  }
276
  lua_settop(L, 0);  /* clear stack */
4✔
277
  fputs("\n", stdout);
4✔
278
  fflush(stdout);
4✔
279
  progname = oldprogname;
4✔
280
}
4✔
281

282
static int handle_script(lua_State *L, char **argx)
289✔
283
{
284
  int status;
289✔
285
  const char *fname = argx[0];
289✔
286
  if (strcmp(fname, "-") == 0 && strcmp(argx[-1], "--") != 0)
289✔
287
    fname = NULL;  /* stdin */
4✔
288
  status = luaL_loadfile(L, fname);
289✔
289
  if (status == LUA_OK) {
289✔
290
    /* Fetch args from arg table. LUA_INIT or -e might have changed them. */
291
    int narg = 0;
288✔
292
    lua_getglobal(L, "arg");
288✔
293
    if (lua_istable(L, -1)) {
288✔
294
      do {
348✔
295
        narg++;
348✔
296
        lua_rawgeti(L, -narg, narg);
348✔
297
      } while (!lua_isnil(L, -1));
348✔
298
      lua_pop(L, 1);
288✔
299
      lua_remove(L, -narg);
288✔
300
      narg--;
288✔
301
    } else {
302
      lua_pop(L, 1);
×
303
    }
304
    status = docall(L, narg, 0);
288✔
305
  }
306
  return report(L, status);
92✔
307
}
308

309
/* Load add-on module. */
310
static int loadjitmodule(lua_State *L)
17✔
311
{
312
  lua_getglobal(L, "require");
17✔
313
  lua_pushliteral(L, "jit.");
17✔
314
  lua_pushvalue(L, -3);
17✔
315
  lua_concat(L, 2);
17✔
316
  if (lua_pcall(L, 1, 1, 0)) {
17✔
317
    const char *msg = lua_tostring(L, -1);
1✔
318
    if (msg && !strncmp(msg, "module ", 7))
1✔
319
      goto nomodule;
1✔
320
    return report(L, 1);
×
321
  }
322
  lua_getfield(L, -1, "start");
16✔
323
  if (lua_isnil(L, -1)) {
16✔
324
  nomodule:
×
325
    l_message("unknown luaJIT command or jit.* modules not installed");
1✔
326
    return 1;
1✔
327
  }
328
  lua_remove(L, -2);  /* Drop module table. */
16✔
329
  return 0;
16✔
330
}
331

332
/* Run command with options. */
333
static int runcmdopt(lua_State *L, const char *opt)
10✔
334
{
335
  int narg = 0;
10✔
336
  if (opt && *opt) {
10✔
337
    for (;;) {  /* Split arguments. */
10✔
338
      const char *p = strchr(opt, ',');
8✔
339
      narg++;
8✔
340
      if (!p) break;
8✔
341
      if (p == opt)
2✔
342
        lua_pushnil(L);
×
343
      else
344
        lua_pushlstring(L, opt, (size_t)(p - opt));
2✔
345
      opt = p + 1;
2✔
346
    }
347
    if (*opt)
6✔
348
      lua_pushstring(L, opt);
6✔
349
    else
350
      lua_pushnil(L);
×
351
  }
352
  return report(L, lua_pcall(L, narg, 0, 0));
10✔
353
}
354

355
/* JIT engine control command: try jit library first or load add-on module. */
356
static int dojitcmd(lua_State *L, const char *cmd)
4✔
357
{
358
  const char *opt = strchr(cmd, '=');
4✔
359
  lua_pushlstring(L, cmd, opt ? (size_t)(opt - cmd) : strlen(cmd));
4✔
360
  lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
4✔
361
  lua_getfield(L, -1, "jit");  /* Get jit.* module table. */
4✔
362
  lua_remove(L, -2);
4✔
363
  lua_pushvalue(L, -2);
4✔
364
  lua_gettable(L, -2);  /* Lookup library function. */
4✔
365
  if (!lua_isfunction(L, -1)) {
4✔
366
    lua_pop(L, 2);  /* Drop non-function and jit.* table, keep module name. */
1✔
367
    if (loadjitmodule(L))
1✔
368
      return 1;
369
  } else {
370
    lua_remove(L, -2);  /* Drop jit.* table. */
3✔
371
  }
372
  lua_remove(L, -2);  /* Drop module name. */
3✔
373
  return runcmdopt(L, opt ? opt+1 : opt);
3✔
374
}
375

376
static int runtoolcmd(lua_State *L, const char *tool_name)
18✔
377
{
378
  lua_getglobal(L, "require");
18✔
379
  lua_pushstring(L, tool_name);
18✔
380
  if (lua_pcall(L, 1, 1, 0)) {
18✔
381
    const char *msg = lua_tostring(L, -1);
×
382
    if (msg) {
×
383
      if (!strncmp(msg, "module ", 7))
×
384
        msg = "unknown luaJIT command or tools not installed";
×
385
      l_message(msg);
×
386
    }
387
    return 1;
×
388
  }
389
  lua_getglobal(L, "arg");
18✔
390
  return report(L, lua_pcall(L, 1, 1, 0));
18✔
391
}
392

393
static int dotoolcmd(lua_State *L, const char *cmd)
394
{
395
  switch (cmd[0]) {
396
  case 'm':
397
    return runtoolcmd(L, "memprof");
398
  case 's':
399
    return runtoolcmd(L, "sysprof");
400
  default:
401
    print_tools_usage();
402
    break;
403
  }
404
  return -1;
405
}
406

407
/* Optimization flags. */
408
static int dojitopt(lua_State *L, const char *opt)
7✔
409
{
410
  lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
7✔
411
  lua_getfield(L, -1, "jit.opt");  /* Get jit.opt.* module table. */
7✔
412
  lua_remove(L, -2);
7✔
413
  lua_getfield(L, -1, "start");
7✔
414
  lua_remove(L, -2);
7✔
415
  return runcmdopt(L, opt);
7✔
416
}
417

418
/* Save or list bytecode. */
419
static int dobytecode(lua_State *L, char **argv)
16✔
420
{
421
  int narg = 0;
16✔
422
  lua_pushliteral(L, "bcsave");
16✔
423
  if (loadjitmodule(L))
16✔
424
    return 1;
425
  if (argv[0][2]) {
16✔
426
    narg++;
4✔
427
    argv[0][1] = '-';
4✔
428
    lua_pushstring(L, argv[0]+1);
4✔
429
  }
430
  for (argv++; *argv != NULL; narg++, argv++)
57✔
431
    lua_pushstring(L, *argv);
41✔
432
  report(L, lua_pcall(L, narg, 0, 0));
16✔
433
  return -1;
16✔
434
}
435

436
/* check that argument has no extra characters at the end */
437
#define notail(x)        {if ((x)[2] != '\0') return -1;}
438

439
#define FLAGS_INTERACTIVE        1
440
#define FLAGS_VERSION                2
441
#define FLAGS_EXEC                4
442
#define FLAGS_OPTION                8
443
#define FLAGS_NOENV                16
444
#define FLAGS_TOOL                32
445

446
static int collectargs(char **argv, int *flags)
363✔
447
{
448
  int i;
363✔
449
  for (i = 1; argv[i] != NULL; i++) {
755✔
450
    if (argv[i][0] != '-')  /* Not an option? */
725✔
451
      return i;
286✔
452
    switch (argv[i][1]) {  /* Check option. */
439✔
453
    case '-':
3✔
454
      notail(argv[i]);
3✔
455
      return i+1;
2✔
456
    case '\0':
457
      return i;
458
    case 'i':
4✔
459
      notail(argv[i]);
4✔
460
      *flags |= FLAGS_INTERACTIVE;
4✔
461
      /* fallthrough */
462
    case 'v':
8✔
463
      notail(argv[i]);
8✔
464
      *flags |= FLAGS_VERSION;
8✔
465
      break;
8✔
466
    case 't':
20✔
467
      *flags |= FLAGS_TOOL;
20✔
468
      return i + 1;
20✔
469
    case 'e':
317✔
470
      *flags |= FLAGS_EXEC;
317✔
471
      /* fallthrough */
472
    case 'j':  /* LuaJIT extension */
378✔
473
    case 'l':
474
      *flags |= FLAGS_OPTION;
378✔
475
      if (argv[i][2] == '\0') {
378✔
476
        i++;
364✔
477
        if (argv[i] == NULL) return -1;
364✔
478
      }
479
      break;
480
    case 'O': break;  /* LuaJIT extension */
481
    case 'b':  /* LuaJIT extension */
16✔
482
      if (*flags) return -1;
16✔
483
      *flags |= FLAGS_EXEC;
16✔
484
      return i+1;
16✔
485
    case 'E':
1✔
486
      *flags |= FLAGS_NOENV;
1✔
487
      break;
1✔
488
    default: return -1;  /* invalid option */
489
    }
490
  }
491
  return i;
492
}
493

494
static int runargs(lua_State *L, char **argv, int argn)
358✔
495
{
496
  int i;
358✔
497
  for (i = 1; i < argn; i++) {
744✔
498
    if (argv[i] == NULL) continue;
430✔
499
    lua_assert(argv[i][0] == '-');
430✔
500
    switch (argv[i][1]) {
430✔
501
    case 'e': {
315✔
502
      const char *chunk = argv[i] + 2;
315✔
503
      if (*chunk == '\0') chunk = argv[++i];
315✔
504
      lua_assert(chunk != NULL);
315✔
505
      if (dostring(L, chunk, "=(command line)") != 0)
315✔
506
        return 1;
507
      break;
508
      }
509
    case 'l': {
57✔
510
      const char *filename = argv[i] + 2;
57✔
511
      if (*filename == '\0') filename = argv[++i];
57✔
512
      lua_assert(filename != NULL);
57✔
513
      if (dolibrary(L, filename))
57✔
514
        return 1;
515
      break;
516
      }
517
    case 'j': {  /* LuaJIT extension. */
4✔
518
      const char *cmd = argv[i] + 2;
4✔
519
      if (*cmd == '\0') cmd = argv[++i];
4✔
520
      lua_assert(cmd != NULL);
4✔
521
      if (dojitcmd(L, cmd))
4✔
522
        return 1;
523
      break;
524
      }
525
    case 't': { /* Tarantool's fork extension. */
20✔
526
      const char *cmd = argv[i] + 2;
20✔
527
      return dotoolcmd(L, cmd) != LUA_OK;
20✔
528
    }
529
    case 'O':  /* LuaJIT extension. */
7✔
530
      if (dojitopt(L, argv[i] + 2))
7✔
531
        return 1;
532
      break;
533
    case 'b':  /* LuaJIT extension. */
16✔
534
      return dobytecode(L, argv+i);
16✔
535
    default: break;
536
    }
537
  }
538
  return LUA_OK;
539
}
540

541
static int handle_luainit(lua_State *L)
357✔
542
{
543
#if LJ_TARGET_CONSOLE
544
  const char *init = NULL;
545
#else
546
  const char *init = getenv(LUA_INIT);
357✔
547
#endif
548
  if (init == NULL)
357✔
549
    return LUA_OK;
550
  else if (init[0] == '@')
×
551
    return dofile(L, init+1);
×
552
  else
553
    return dostring(L, init, "=" LUA_INIT);
×
554
}
555

556
static struct Smain {
557
  char **argv;
558
  int argc;
559
  int status;
560
} smain;
561

562
static int pmain(lua_State *L)
363✔
563
{
564
  struct Smain *s = &smain;
363✔
565
  char **argv = s->argv;
363✔
566
  int argn;
363✔
567
  int flags = 0;
363✔
568
  globalL = L;
363✔
569

570
  LUAJIT_VERSION_SYM();  /* Linker-enforced version check. */
363✔
571

572
  argn = collectargs(argv, &flags);
363✔
573
  if (argn < 0) {  /* Invalid args? */
363✔
574
    print_usage();
5✔
575
    s->status = 1;
5✔
576
    return 0;
5✔
577
  }
578

579
  if ((flags & FLAGS_NOENV)) {
358✔
580
    lua_pushboolean(L, 1);
1✔
581
    lua_setfield(L, LUA_REGISTRYINDEX, "LUA_NOENV");
1✔
582
  }
583

584
  /* Stop collector during library initialization. */
585
  lua_gc(L, LUA_GCSTOP, 0);
358✔
586
  luaL_openlibs(L);
358✔
587
  lua_gc(L, LUA_GCRESTART, -1);
358✔
588

589
  createargtable(L, argv, s->argc, (flags & FLAGS_TOOL) ? argn - 1 : argn);
358✔
590

591
  if (!(flags & FLAGS_NOENV)) {
358✔
592
    s->status = handle_luainit(L);
357✔
593
    if (s->status != LUA_OK) return 0;
357✔
594
  }
595

596
  if ((flags & FLAGS_VERSION)) print_version();
358✔
597

598
  s->status = runargs(L, argv, argn);
358✔
599
  if (s->status != LUA_OK) return 0;
337✔
600

601
  if (s->argc > argn) {
314✔
602
    s->status = handle_script(L, argv + argn);
289✔
603
    if (s->status != LUA_OK) return 0;
92✔
604
  }
605

606
  if ((flags & FLAGS_INTERACTIVE)) {
115✔
607
    print_jit_status(L);
4✔
608
    dotty(L);
4✔
609
  } else if (s->argc == argn && !(flags & (FLAGS_EXEC|FLAGS_VERSION))) {
111✔
610
    if (lua_stdin_is_tty()) {
1✔
611
      print_version();
×
612
      print_jit_status(L);
×
613
      dotty(L);
×
614
    } else {
615
      dofile(L, NULL);  /* Executes stdin as a file. */
1✔
616
    }
617
  }
618
  return 0;
619
}
620

621
int main(int argc, char **argv)
363✔
622
{
623
  int status;
363✔
624
  lua_State *L;
363✔
625
  if (!argv[0]) argv = empty_argv; else if (argv[0][0]) progname = argv[0];
363✔
626
  L = lua_open();  /* create state */
363✔
627
  if (L == NULL) {
363✔
628
    l_message("cannot create state: not enough memory");
×
629
    return EXIT_FAILURE;
×
630
  }
631
  smain.argc = argc;
363✔
632
  smain.argv = argv;
363✔
633
  status = lua_cpcall(L, pmain, NULL);
363✔
634
  report(L, status);
145✔
635
  lua_close(L);
145✔
636
  return (status || smain.status > 0) ? EXIT_FAILURE : EXIT_SUCCESS;
145✔
637
}
638

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc