开vs2008 命令行窗口
C:\>cd /d d:
D:\>cd D:\c32\LuaJIT-2.0.3\src
D:\c32\LuaJIT-2.0.3\src>msvcbuild.bat
D:\c32\LuaJIT-2.0.3\src>luajit
dofile("hi.lua")
------------------------------------------------------------------------
hi.lua
local ffi = require "ffi"
assert(ffi ~= nil)
local hi = ffi.load('libhi.dll', true)
assert(hi ~= nil)
ffi.cdef[[
int barfunc(int foo);
]]
hi.barfunc(1)
print ("hi!!")
------------------------------------------------------------------------
------------------------------------------------------------------------
libhi.cpp
#include "lua.hpp"
extern "C" {
__declspec(dllexport) int __cdecl barfunc(int foo) {
return foo + 1;
}
}
---------------------------------------------------------------------------