积木

No sub title

  C++博客 :: 首页 :: 联系 :: 聚合  :: 管理
  140 Posts :: 1 Stories :: 11 Comments :: 0 Trackbacks

常用链接

留言簿(1)

我参与的团队

搜索

  •  

最新评论

阅读排行榜

评论排行榜

 

 1 
 2 #include "stdafx.h"
 3 
 4 #include <iostream>
 5 using namespace std;
 6 
 7 extern "C"{
 8 #include "lua.h"
 9 #include "lualib.h"
10 #include "lauxlib.h"
11 }
12 
13 lua_State *L;
14 
15 int _tmain(int argc, _TCHAR* argv[])
16 {
17     //* 创建一个指向Lua解释器的指针。
18     L = lua_open();
19     //* 函数加载Lua库
20     luaL_openlibs(L);
21     //* 加载Lua脚本
22     luaL_dofile(L, "../TestException/add.lua");
23 
24         int x = 3, y = 8;
25         //函数名
26         lua_getglobal(L, "add");
27         //第一个参数压栈
28         lua_pushnumber(L, x);
29         //第二个参数压栈
30         lua_pushnumber(L, y);
31         //调用函数
32         lua_call(L, 21);
33         //得到返回值
34         int sum = (int)lua_tonumber(L, -1);
35         lua_pop(L, 1);
36         cout << sum << endl;
37 
38     //* 关闭释放资源
39     lua_close(L);
40 
41     waitplease;
42     return 0;
43 }
44 
45 

 

posted on 2012-12-08 12:49 Jacc.Kim 阅读(315) 评论(0)  编辑 收藏 引用 所属分类: Lua

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理