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
- D:\LUA>lua hello.lua
- hello world
-
- D:\>lua
- > print("hello")
- hello
-
- D:\>lua d:/lua/hello.lua
- hello world
Simple interpreter code 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;
- }
Summary: AnalysisLua interpreterThe content of the running method learning tutorial is complete. I hope this article will help you!