How to parse the Lua interpreter

Source: Internet
Author: User

Lua interpreterThe running method learning tutorial is the content to be introduced in this article, mainly to understandLUA interpreterAboutInterpreterLet's take a look at the details.

1. Run lua.exe directly and enter the lua statement, such as print ("hello world ")

2. Write print ("hello world" into a file named hello.lua, and put it on the d drive. Then you can open lua.exe and run dofile ("d:/hello. lua") -- previously written as DoFile, which turns out to be lowercase dofile ),Lua interpreterThe command in the file will be executed.

3. Use a command prompt to directly run cmd

 
 
  1. D:\LUA>lua hello.lua  
  2. hello world  
  3.  
  4. D:\>lua  
  5. > print("hello")  
  6. hello  
  7.  
  8. D:\>lua d:/lua/hello.lua  
  9. hello world 

Simple interpreter code C ++)

 
 
  1. #include <stdio.h> 
  2. #include <string.h> 
  3. #include "lua.hpp"  
  4. #include "luaconf.h"  
  5.  
  6. int main (void)  
  7. {  
  8.  char buff[256];  
  9.  int error;  
  10.  
  11.  lua_State *L = lua_open();   
  12.  
  13.  luaopen_base(L);     
  14.  luaopen_table(L);     
  15.  
  16.  luaopen_string(L);     
  17.  luaopen_math(L);     
  18.  
  19.  while (fgets(buff, sizeof(buff), stdin) != NULL)  
  20.  {  
  21.   error = luaL_loadbuffer(L, buff, strlen(buff), "line") || lua_pcall(L, 0, 0, 0);  
  22.   if (error)  
  23.   {  
  24.    fprintf(stderr, "%s", lua_tostring(L, -1));  
  25.    lua_pop(L, 1);  
  26.   }  
  27.  }  
  28.  
  29.  lua_close(L);  
  30.  return 0;  

Summary: AnalysisLua interpreterThe content of the running method learning tutorial is complete. I hope this article will help you!

Related Article

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.