今天碰上一个人在那里说了一下在LUA里面加载DLL的模块,因为没有接触过,也就去试了一下,其实挺简单。 1 5.1 Hello World
2 新建一个控制台DLL工程, 名字是 luabind_test. 3 4 #include <iostream> 5 #include <luabind/luabind.hpp> 6 #include <luabind/lua_include.hpp> 7 8 extern "C" 9 { 10 #include "lua.h" 11 #include "lauxlib.h" 12 } 13 14 void greet() 15 { 16 std::cout << "hello world!\n"; 17 } 18 19 extern "C" int luaopen_luabind_test(lua_State* L) 20 { 21 using namespace luabind; 22 23 open(L); 24 25 module(L) 26 [ 27 def("greet", &greet) 28 ]; 29 30 return 0; 31 } 32 33 34 35 把生成的DLL和lua.exe/lua51.dll放在同一个目录下. 36 37 Lua 5.1.2 Copyright (C) 1994-2007 Lua.org, PUC-Rio 38 > require "luabind_test" 39 > greet() 40 Hello world! 41 > 42 http://www.inf./~roberto/pil2/chapter15.pdf http://blog.csdn.net/linkerlin/archive/2008/04/06/2254725.aspx |
|