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