锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
--test.lua
function printColor()
colour = ColourValue(1, 1, 1, 1);
colour:printColor();
end
Config = 

{
color = ColourValue(1, 1, 1, 1),
count = 5,
fun = printColor
}
class ColourValue

{
public:
ColourValue(float r = 1.0,
float g = 1.0,
float b = 1.0,
float a = 1.0) : mR(r), mB(b), mG(g), mA(a)
{
}
void printColor()
{
cout << mR << ", "
<< mG << ", "
<< mB << ", "
<< mA << ", "
<< endl;
}
protected:
float mR;
float mG;
float mB;
float mA;
};
// 鍙栧緱鍏ㄥ眬琛ㄥ璞°?/span>
luabind::object global = luabind::globals(L);
// 鑾峰彇鑴氭湰涓殑Config琛ㄣ?/span>
luabind::object configTable = global["Config"];
// 璁塊棶Config琛ㄤ腑鐨刢olor銆?/span>
ColourValue color = luabind::object_cast<ColourValue>(configTable["color"]);
// 璁塊棶Config琛ㄤ腑count銆?/span>
int count = luabind::object_cast<int>(configTable["count"]);
// 璁塊棶Config琛ㄤ腑鐨刾rintColor鍑芥暟銆?/span>
luabind::object printColor = configTable["fun"];
printColor(); // 絎竴縐嶈皟鐢ㄦ柟娉曘?/span>
luabind::call_function<void>(printColor); // 絎簩縐嶈皟鐢ㄦ柟娉曘?/span>
#include "stdafx.h"
#include <iostream>
#include <luabind/luabind.hpp>
void greet()

{
std::cout << "hello world!\n";
}
extern "C" int __declspec(dllexport) init(lua_State* L)

{
using namespace luabind;
open(L);
module(L)
[
def("greet", &greet)
];
return 0;
}
娉ㄦ剰錛屽湪Windows鐜涓媔nit鍑芥暟涔嬪墠鏄鍔燺_declspec(dllexport)鎵嶈兘灝嗗嚱鏁板鍑虹殑錛岃宭uabind鐨勬枃妗d腑鐨勭幆澧冩槸linux錛岄粯璁や笉鐢ㄥ姞__declspec(dllexport)涔熷彲浠ュ鍑?灝卞洜涓鴻繖涓姌鑵句簡鎴戝崐澶╂墠鎶奾ello word鎴愬姛榪愯)銆?br> 緙栬瘧欏圭洰錛?璁板緱灝唋uabind.lib鍜宭ua51.lib娣誨姞鍒伴摼鎺ラ夐」涓細欏圭洰灞炴?>榪炴帴鍣?>杈撳叆->闄勫姞渚濊禆鏂囦歡錛屽姞鍏uabind.lib鍜宭ua51.lib)銆?br> 灝唄ello world.dll鏀懼埌lua51.dll鍜宭ua.exe鎵鍦ㄧ殑鐩綍涓嬨?br> 鎵撳紑lua鍛戒護琛岋紝閿叆:

嫻嬭瘯鎴愬姛錛宔njoy銆?/font>