Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ Lua4.0 interpreter entrance     - Shell for loop (Programming)

- Android Unzip the ZIP / GZIP data (based on the InflaterInputStream implementation) (Programming)

- Solve the compatibility problem between Linux and Java at the source in bold font (Linux)

- Installation GitLab appears ruby_block supervise_redis_sleep action run (Linux)

- Linux virtual machine how to access the Internet in a virtual machine when using NAT mode (Linux)

- FileZilla install on Ubuntu 14.10 (Linux)

- CentOS 6.0 system security level (Linux)

- Deploy OpenStack Juno on Ubuntu 14.04 (Linux)

- ethtool implementation framework and application in Linux (Linux)

- php How to prevent being injected (Linux)

- Linux system started to learn: Teaches you install Fedora 22 on VirtualBox (Linux)

- PHP file upload methods exist in the database (Programming)

- Archlinux installation tutorial (Linux)

- Wine 1.7 is installed on a system based on RedHat or Debian (Linux)

- using Docker Kitematic on windows (Linux)

- Linux operating system Study Notes (Linux)

- First start with Kali Linux 2.0 (Linux)

- Ubuntu the ARP (arptables) (Linux)

- Linux loopback adapter Driven Design (Programming)

- Check the Linux server performance with ten or so commands in a minute (Server)

  Lua4.0 interpreter entrance
  Add Date : 2017-08-31      
  Start the interpreter.

Interpreter entry file lua.c, find the main C language in the document.

int main (int argc, char * argv []) {
  struct Options opt;
  int status;
  opt.toclose = 0;
  getstacksize (argc, argv, & opt); / * handle option `-s' * /
  L = lua_open (opt.stacksize); / * create state * /
  userinit (); / * open libraries * /
  register_getargs (argv); / * create `getargs' function * /
  status = handle_argv (argv + 1, & opt);
  if (opt.toclose)
    lua_close (L);
  return status;

Setting structure struct Options stack size stacksize.

Struct Options structure defined as follows:

/ *
** Global options
* /
struct Options {
  int toclose;
  int stacksize;

In the getstacksize to stacksize assignment. You need to pass command line "-s" parameter.

lua_open New lua_State L.

userinit registry.

register_getargs Sign up for command line input parameter function getargs.

handle_argv program execution.

toclose If 1, then, before the program exits to call lua

Return status of program execution.

Wherein each facie call:

static void getstacksize (int argc, char * argv [], struct Options * opt) {
  if (argc> = 2 && argv [1] [0] == '-' && argv [1] [1] == 's') {
    int stacksize = atoi (& argv [1] [2]);
    if (stacksize <= 0) {
      fprintf (stderr, "lua: invalid stack size ( '% .20s') \ n", & argv [1] [2]);
      exit (EXIT_FAILURE);
    opt-> stacksize = stacksize;
    opt-> stacksize = 0; / * no stack size * /

If the command line parameter "-s", take it back as a value struct Options of stacksize.

static void userinit (void) {
  lua_baselibopen (L);
  lua_iolibopen (L);
  lua_strlibopen (L);
  lua_mathlibopen (L);
  lua_dblibopen (L);
  / * Add your libraries here * /

This is a call to all kinds of library registration function.

Next is registered getargs function

static void register_getargs (char * argv []) {
  lua_pushuserdata (L, argv);
  lua_pushcclosure (L, l_getargs, 1);
  lua_setglobal (L, "getargs");

The command line parameters push, push the function l_getargs set to Lua variables getargs.

Then call getargs in Lua code will call a C function l_getargs this.

Implementation l_getargs this time a function call is as follows:

static void getargs (char * argv []) {
  int i;
  lua_newtable (L);
  for (i = 0; argv [i]; i ++) {
    / * Arg [i] = argv [i] * /
    lua_pushnumber (L, i);
    lua_pushstring (L, argv [i]);
    lua_settable (L, -3);
  / * Arg.n = maximum index in table `arg '* /
  lua_pushstring (L, "n");
  lua_pushnumber (L, i-1);
  lua_settable (L, -3);
static int l_getargs (lua_State * l) {
  char ** argv = (char **) lua_touserdata (l, -1);
  getargs (argv);
  return 1;

Get a userdata from the stack, which made all the command line parameters getargs.

Command-line arguments are made in the presence of a Lua table.

handle_argv parse the command line arguments, the main process execution.

The main part of the program is a big loop judge to resolve the various parameters.

manual_input used for interactive processing modes, other files and string handling performed by the ldo.

manual_input program is a loop, to perform user input by calling ldo (lua_dostring, buffer).

ldo follows:

static int ldo (int (* f) (lua_State * l, const char *), const char * name) {
  int res;
  handler h = lreset ();
  int top = lua_gettop (L);
  res = f (L, name); / * dostring | dofile * /
  lua_settop (L, top); / * remove eventual results * /
  signal (SIGINT, h); / * restore old action * /
  / * Lua gives no message in such cases, so lua.c provides one * /
  if (res == LUA_ERRMEM) {
    fprintf (stderr, "lua: memory allocation error \ n");
  else if (res == LUA_ERRERR)
    fprintf (stderr, "lua: error in error message \ n");
  return res;

The first parameter is a function pointer can be passed lua_dofile, lua_dostring respectively correspond to the input file and string input.

The second parameter depending on the first function pointer and can mean different things: a file name or a string.

By calling lreset () sets the interrupt signal handler.

At the end of the call signal (SIGINT, h) to restore the interrupt signal processing.

Interpreter inlet stop here.


So far the problem:

> Lua_dofile, lua_dostring

- SSH without password (Linux)
- Detailed usage history command (Linux)
- SQL statement to repair SQL Server database (Database)
- Tsung first test installation (Linux)
- Swift defined type conversion and type aliases (typealias) (Programming)
- Basic Tutorial: Linux novice should know 26 commands (Linux)
- Installation and use Docker under Ubuntu 14.04 (Linux)
- Definition Format Oracle basis of various statements (Database)
- MySQL query performance comparison of a single truth (Database)
- Shell command line operation (Linux)
- ImportTsv-HBase data import tool (Database)
- TNS-03505 name could not be resolved (Database)
- Squid proxy server configuration under Linux (Server)
- Ubuntu 14.04 set auto sleep time (Linux)
- Install NetBeans IDE 8.0 on Ubuntu, Linux Mint, Elementary OS, and Debian (Linux)
- Use PuTTY key authentication mechanism for remote login Linux (Linux)
- How to use tmpfs in RHEL / CentOS 7.0 (Linux)
- Bash added to the Vi mode indicator (Linux)
- ORA-12154: TNS: could not resolve the connect identifier specified solve (Database)
- LNMP Note: Addressing mail function can not send mail (Server)
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.