解析Lua解譯器運行方法學習教程

來源:互聯網
上載者:User

Lua解譯器運行方法學習教程是本文要介紹的內容,主要是來瞭解LUA解譯器的使用方法,關於解譯器如何來運行,那麼一起來看內容詳解。

1、直接運行lua.exe,輸入lua語句,比如print("hello world")

2、將print("hello world")寫進一個名為hello.lua的檔案裡,假設放在D盤,然後可以開啟lua.exe後運行dofile("d:/hello.lua")--之前寫成了DoFile,事實證明得小寫dofile),lua解譯器就會執行這個檔案內的指令。

3、使用命令提示字元,即直接運行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 

簡易解譯器代碼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;  

小結:解析Lua解譯器運行方法學習教程的內容介紹完了,希望通過本文的學習能對你有所協助!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.