在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
Original link: http://sunxiunan.com/?p=1498
You could download the project from http://groups.google.com/group/lua5/web/luautil.rar At first, create a windows dll application. The IDE I used is VC2008.
I suggest you download and install the "Lua for windows " from luaforge.net, it contains most useful packages for Lua windows development. You could copy "include" and "lib" directory under the installation directory to your project.
In the beginning, you should include Lua header files.
Please note, you should use extern "C" to declare the header for Lua. In linker’s input, set the lua51.lib.
The project should have a function like luaopen_xxx (in my code, it is luaopen_luautil), and have strings=>functions map structure like "lua_util". Then you could call your extension like require "luautil".
The L_MSleep will call windows’ api Sleep().
Another function L_NewTable will generate a complex table for Lua script. It will call lua_settable() and lua_setfield() function to manipulate the table in Lua. lua_pushstring() and lua_pushnumber() could push string type and number type data to Lua. You could find the document about these functions in Lua 5.1 manual.
The table that Lua get will like:
local table1 = {
After you build the project, copy the dll to lua installation folder "lua\5.1\clibs".
In the end, we could test the extension like:
require "luautil" for k, v in pairs(newtable) do
– sleep 5 seconds. |
请发表评论