2014-10-09 51 views
1

我正在試驗將LUA與luabind集成到我的程序中,但是我遇到了一個很大的絆腳石。C++ 11 luabind集成,函數失敗

我很不熟悉LUA的調用約定,我覺得我錯過了一些簡單的東西。

這裏是我的C++代碼:

struct app_t 
{ 
    //... 
    void exit(); 
    void reset(); 

    resource_mgr_t resources; 
    //... 
}; 

struct resource_mgr_t 
{ 
    //... 
    void prune(); 
    void purge(); 
    //... 
}; 

extern app_t app; 

而且我luabind模塊:

luabind::module(state) 
    [ 
     luabind::class_<resource_mgr_t>("resource_mgr") 
     .def("prune", &resource_mgr_t::prune) 
     .def("purge", &resource_mgr_t::purge) 
    ]; 

luabind::module(state) 
    [ 
     luabind::class_<app_t>("app") 
     .def("exit", &app_t::exit) 
     .def("reset", &app_t::reset) 
     .def_readonly("resources", &app_t::resources) 
    ]; 

luabind::globals(state)["app"] = &app; 

我可以執行以下LUA命令就好了:

app:exit() 
app:reset() 

但是,以下致電失敗:

app.resources:purge() 

,出現以下錯誤:

[string "app.resources:purge()"]:1: attempt to index field 'resources' (a function value) 

任何幫助是非常感謝!

回答

1

When binding members that are a non-primitive type, the auto generated getter function will return a reference to it.

而且,就像在app:reset(),資源是一個實例成員字段。

所以,像這樣使用:

app:resources():purge() 
+0

'應用:資源():清除()'現在產生了運行時錯誤'luabind:property_tag功能不能called'。 – 2014-10-09 16:07:32

+0

嘗試'app.resources():purge()'。 (我現在無法測試) – 2014-10-09 16:09:33

+0

我得到了同樣的錯誤:(顯然我可能需要重建luabind庫(http://www.gamedev.net/topic/593408-def-readwrite-dosent-work /)我一直在遇到奇怪的錯誤,比如僅僅包含導致程序不能編譯的''。 – 2014-10-09 16:12:28