Lua1.0 code analysis inout. c

Source: Internet
Author: User

Inout. C code analysis

Mainly look at the processing of files

/*** Function to open a file to be input unit.** Return 0 on success or 1 on error.*/int lua_openfile (char *fn){ lua_linenumber = 1; lua_setinput (fileinput); lua_setunput (fileunput); fp = fopen (fn, "r"); if (fp == NULL) return 1; if (lua_addfile (fn)) return 1; return 0;}

Input the script file name and set the current input Behavior 1
Set File Read and put back.
Open the file and set the file handle.
Add the file to the file list. Lua_addfile is defined in Table. C and will be analyzed in table. C.

/*** Function to get the next character from the input file*/static int fileinput (void){ int c = fgetc (fp); return (c == EOF ? 0 : c);}

Read a character from the file handle

/*** Function to unget the next character from to input file*/static void fileunput (int c){ ungetc (c, fp);}

Put a character back into the file handle

Int lua_openstring (char * s) is similar to lua_openfile, except that the file name is represented by a string starting with "string.

/*** Called to execute SETFUNCTION opcode, this function pushs a function into** function stack. Return 0 on success or 1 on error.*/int lua_pushfunction (int file, int function){ if (nfuncstack >= MAXFUNCSTACK-1) {  lua_error ("function stack overflow");  return 1; } funcstack[nfuncstack].file = file; funcstack[nfuncstack].function = function; nfuncstack++; return 0;}

Set the functions in the script to the function stack. Record the file name and function address.

Lua1.0 code analysis inout. c

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.