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
- D:\LUA>lua hello.lua
- hello world
-
- D:\>lua
- > print("hello")
- hello
-
- D:\>lua d:/lua/hello.lua
- hello world
簡易解譯器代碼C++)
- #include <stdio.h>
- #include <string.h>
- #include "lua.hpp"
- #include "luaconf.h"
-
- int main (void)
- {
- char buff[256];
- int error;
-
- lua_State *L = lua_open();
-
- luaopen_base(L);
- luaopen_table(L);
-
- luaopen_string(L);
- luaopen_math(L);
-
- while (fgets(buff, sizeof(buff), stdin) != NULL)
- {
- error = luaL_loadbuffer(L, buff, strlen(buff), "line") || lua_pcall(L, 0, 0, 0);
- if (error)
- {
- fprintf(stderr, "%s", lua_tostring(L, -1));
- lua_pop(L, 1);
- }
- }
-
- lua_close(L);
- return 0;
- }
小結:解析Lua解譯器運行方法學習教程的內容介紹完了,希望通過本文的學習能對你有所協助!