Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ Lua4.0 interpreter entrance     - sudoers file parsing (Linux)

- Linux installation is larger than 2TB (UEFI interface) hard disk solution (Linux)

- Linux operating system security management skills (Linux)

- Memcached source installation and configuration under CentOS 6.6 (Server)

- Linux asynchronous read documents by AIO (Programming)

- SSH port forwarding application (Server)

- AngularJS - Custom instructions (Programming)

- Linux Network Statistics Tools / Command (Linux)

- CentOS 6 compiling httpd-2.4.10 (Server)

- Installation and Configuration rsync server under CentOS 6.3 (Server)

- Unix average load average load calculation method (Server)

- expdp reported ORA-39181 Export Processing Method (Database)

- Gentoo: !!! existing preserved libs problem (Linux)

- Enterprise Hadoop cluster architecture - NFS installation (Server)

- Ubuntu UFW firewall settings Introduction (Linux)

- CentOS5 installation Nodejs (Linux)

- MariaDB 10.0.X, the dynamic column support JSON format to obtain data (Database)

- Composition and dynamic memory allocation C program (Programming)

- LNMP Note: Addressing mail function can not send mail (Server)

- Java framework for parallel study - ForkJoin (Programming)

  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

- Ubuntu 15.10 15.04 14.10 14.04 Install Ubuntu Tweak (Linux)
- Nginx installation configuration Zabbix (Server)
- Security basics: simple analytical framework for Linux system firewall (Linux)
- Nodejs command-line program development tutorial (Programming)
- Monitoring services are running properly and will email alert (Server)
- Circular list of Java programming (Programming)
- Qt for file splitting and fusion gadgets (Programming)
- How to defragment the hard disk in Linux (Linux)
- jQuery plugin dynamic label generation (Linux)
- Detailed Linux network security policies and protection measures (Linux)
- To install the Oracle process notes on Oracle Linux 4u4 (Database)
- Linux instructions and examples GPG encryption and decryption (Linux)
- Linux environment Duplex (multi-machine) automatic mutual backup scheme (Linux)
- Examples of testing and installation Mesos on CentOS (Linux)
- Interesting example of Linux Sort command (Linux)
- Recover Ubuntu 14.04 wakes up from standby in case mouse keyboard appears dead (Linux)
- Use the command line MySQL database backup and recovery (Database)
- Ubuntu development Nodejs (Linux)
- Using IntelliJ IDEA Import Spark Spark latest source code and compile the source code (Linux)
- Why HBase need to build SQL engine layer (Database)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.