解析Lua解释器运行方法学习教程

移动开发 iOS
Lua解释器运行方法学习教程是本文要介绍的内容,主要是来了解LUA解释器的使用方法,关于解释器如何来运行,那么一起来看内容详解。

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解释器运行方法学习教程的内容介绍完了,希望通过本文的学习能对你有所帮助!

责任编辑:zhaolei 来源: 互联网
相关推荐

2011-08-23 15:57:21

Lua元表元方法

2011-08-24 09:49:38

VS2008Lua解释器

2011-08-24 15:22:09

2011-08-25 16:38:06

EditPluslua

2011-08-31 17:35:18

Lua解释器Script.NET

2011-08-24 11:08:09

Lua

2011-08-23 16:48:41

Lua 5.1API 函数

2009-12-03 09:59:34

2011-08-23 13:27:46

Luaglobal变量

2011-08-24 15:28:02

Lua编译器解释器

2011-08-23 17:11:13

Lua事件C#

2011-08-25 13:44:11

LUA下载SciTE

2011-08-29 18:09:45

LUAWeb开发服务器

2009-08-31 16:51:11

C# Main()方法

2009-08-27 09:27:49

C#扩展方法

2009-08-21 18:01:32

C#匿名方法

2009-08-12 17:32:44

C#反射方法

2009-08-14 17:38:08

C#改写方法

2011-08-23 15:34:56

Lua模式 匹配

2011-08-24 11:03:33

LUA环境 安装
点赞
收藏

51CTO技术栈公众号