lua 学习笔记12

lua 学习笔记12

/******************/
  在c++中使用lua
/******************/
费了九牛二虎之力,总算可以在vs 2003的c++环境中使用lua了。
方法如下:
1、解压缩下载的lua原文件包 ,把其ect目录下的luavs.bat,拷贝到lua目录下,在vs2003的命令行工具中运行它,生成编译好的文件。
2、在vs2003中建立一个控制台项目,把刚才生成的一堆src目录下的文件拷到这个项目下,新建一个main.cpp文件,写入如下内容:
#include <stdio.h>
#include <string.h>
extern"C"{
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
}
int main(void){
   char buff[256];
      int error;
      lua_State *L = lua_open();   /* opens Lua */
      luaopen_base(L);             /* opens the basic library */
      luaopen_table(L);            /* opens the table library */
      luaopen_io(L);               /* opens the I/O library */
      luaopen_string(L);           /* opens the string lib. */
      luaopen_math(L);             /* opens the math lib. */
   
      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);  /* pop error message from the stack */
        }
      }
   
      lua_close(L);
      return 0;
}
3、打开vs的视图-〉属性页,进入连接器-〉输入,在里面附加依赖项里写入lua51.lib。
4、ok,按F7编译。
done!

2 thoughts on “lua 学习笔记12

  1. Hi,Do you have used LCD monitors, second hand lcd monitors and second hand flat screens? Please go here:www.sstar-hk.com(Southern Stars).We are constantly buying re-usable LCD panels,LCD recycle.The re-usable panels go through strictly designed process of categorizing, checking, testing, repairing and refurbishing before they are re-used to make remanufactured LCD displays and TV sets.Due to our recent breakthrough in testing and repairing technology of LCD, we can improve the value for your LCD panels.
    Contact Us
    E-mail:sstar@netvigator.com
    website:www.sstar-hk.com[i

  2. wow gold
    wow gold
    wow gold
    wow gold
    wow gold
    wow gold
    wow gold
    wow gold
    wow gold
    wow gold
    wow gold
    wow gold
    wow gold
    wow gold
    wow gold
    wow gold
    wow gold
    wow gold
    wow gold
    wow gold
    wow gold
    wow gold
    wow gold
    wow gold
    wow gold
    wow gold
    wow gold
    wow gold
    wow gold
    wow gold
    wow gold
    wow gold
    wow gold
    wow gold
    wow gold
    wow gold -229152394089451

Leave a Reply

Your email address will not be published. Required fields are marked *