• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            3D FPS

            1234567890

              C++博客 :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
              57 Posts :: 2 Stories :: 57 Comments :: 0 Trackbacks

            常用鏈接

            留言簿(10)

            我參與的團(tuán)隊(duì)

            搜索

            •  

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            lua 的包裝庫好多 巨形的就算是luabind 因?yàn)橐觔oost  boost里的mpl 模板元編程 還真TMD封裝嚇?biāo)廊?br>
            這里轉(zhuǎn)載了一下這個(gè)高手的 http://www.nuclex.org/articles/quick-introduction-to-luabind

            這里是他的源碼 看看吧 copyleft not me 版拳 非我
            // --------------------------------------------------------------------------------------------- //
            // LuaBind example
            //
            // This example project for Microsoft(tm) Visual C++ 2008(tm) users
            // compiles out-of-the-box. Precompiled binaries can be found in the
            // "References" directory in case you wish to use them for other
            // projects. Pay attention to the runtime library (multithreaded dll)
            // setting and the different library files being used for debug and release
            // builds when you do so!
            // 注意要多線程
            // --------------------------------------------------------------------------------------------- //

            // Include the lua headers (the extern "C" is a requirement because we're
            // using C++ and lua has been compiled as C code)
            extern "C" {
            #include "lua.h"
            #include "lualib.h"
            #include "lauxlib.h"
            }

            // This is the only header we need to include for LuaBind to work
            #include "luabind/luabind.hpp"

            // Some other C++ headers we're most likely going to use
            #include <iostream>
            #include <string>

            // We don't want to write std:: every time we're displaying some debug output
            using namespace std;

            // --------------------------------------------------------------------------------------------- //

            // Put your testing code here...

            // 這個(gè)里面一共有X個(gè)示例調(diào)用luabind注冊(cè)C++的Function && class to lua

            // 一個(gè)C++函數(shù)
            void print_hello(int number) {
            cout << "hello world " << number << endl;
            }

            // 一個(gè)C++類
            class NumberPrinter {
            public:
            NumberPrinter(int number) :
            m_number(number) {}

            void print() {
            cout << m_number << endl;
            }

            private:
            int m_number;
            };

            // 一個(gè)模板類
            template<typename T>
            struct Point {
            Point(T X, T Y) :
            X(X), Y(Y) {}
            T X, Y;
            };

            //一個(gè)模板的模板類
            template<typename T>
            struct Box {
            Box(Point<T> UpperLeft, Point<T> LowerRight) :
            UpperLeft(UpperLeft), LowerRight(LowerRight) {}
            Point<T> UpperLeft, LowerRight;
            };

            // 資源管理類
            struct ResourceManager {
            ResourceManager() :
            m_ResourceCount(0) {}

            void loadResource(const string &sFilename) {
            ++m_ResourceCount;
            }
            size_t getResourceCount() const {
            return m_ResourceCount;
            }
            size_t m_ResourceCount;
            };


            //注冊(cè)c++的東西到lua里去都是用lua::module lua::def 的
            //關(guān)鍵看的就是這個(gè) module def的寫法
            //注冊(cè)函數(shù):luabind::module(L) [ luabind::def("print_hello", print_hello)];
            // 估計(jì)是注冊(cè)了一個(gè)lua函數(shù)
            //注冊(cè)類 :luabind::module(L) [luabind::class_<NumberPrinter>("NumberPrinter") .def(luabind::constructor<int>()).def("print", &NumberPrinter::print)];
            // 估計(jì)是

            int main() {

            //初創(chuàng)建一個(gè)lua_state
            lua_State *myLuaState = lua_open();

            // Connect LuaBind to this lua state
            luabind::open(myLuaState);

            //2//注冊(cè)C++函數(shù)到lua
            //void print_hello(int number) {cout << "hello world " << number << endl;} 要放全局
            luabind::module(myLuaState) [
            luabind::def("print_hello", print_hello),

            luabind::class_<NumberPrinter>("NumberPrinter")
            .def(luabind::constructor<int>())
            .def("print", &NumberPrinter::print),

            luabind::class_<Point<float> >("Point")
            .def(luabind::constructor<float, float>())
            .def_readwrite("X", &Point<float>::X)
            .def_readwrite("Y", &Point<float>::Y),

            luabind::class_<Box<float> >("Box")
            .def(luabind::constructor<Point<float>, Point<float> >())
            .def_readwrite("UpperLeft", &Box<float>::UpperLeft)
            .def_readwrite("LowerRight", &Box<float>::LowerRight)
            ];

            luaL_dostring(
            myLuaState,

            "function add(first, second)\n"
            " return first + second\n"
            "end\n"

            "print_hello(123)\n"

            "Print2000 = NumberPrinter(2000)\n"
            "Print2000:print()\n"

            "MyBox = Box(Point(10, 20), Point(30, 40))\n"
            "MyBox.UpperLeft.X = MyBox.LowerRight.Y\n"
            );


            cout << "Result: "<< luabind::call_function<int>(myLuaState, "add", 2, 3) << endl;


            lua_close(myLuaState);
            getchar();
            return 0;


            }

            posted on 2008-08-02 22:20 DK_jims 閱讀(1470) 評(píng)論(0)  編輯 收藏 引用 所屬分類: lua
            久久无码精品一区二区三区| 一级a性色生活片久久无少妇一级婬片免费放| 美女久久久久久| 亚洲人成电影网站久久| 性欧美丰满熟妇XXXX性久久久| 人人狠狠综合久久88成人| 国产午夜福利精品久久| 97精品国产97久久久久久免费 | 999久久久国产精品| 亚洲欧美成人久久综合中文网| 777午夜精品久久av蜜臀| 青青草原综合久久| 亚洲国产精品无码久久一线| 久久人人爽人人爽人人片AV麻豆| 久久久久亚洲Av无码专| 日韩欧美亚洲综合久久影院Ds| 国内精品久久久久影院日本| 四虎久久影院| 精品无码久久久久久久久久| 久久久精品人妻一区二区三区蜜桃| 人人狠狠综合久久亚洲| 精品精品国产自在久久高清| 亚洲AV无码久久精品成人| 亚洲国产成人精品女人久久久 | 四虎亚洲国产成人久久精品| 久久国产精品-久久精品| 精品国产乱码久久久久久呢| 欧美久久综合九色综合| 精品久久久久久99人妻| 伊人久久大香线蕉影院95| 久久精品www人人爽人人| 国色天香久久久久久久小说| 一本久久综合亚洲鲁鲁五月天| 日本久久久精品中文字幕| 99久久久精品免费观看国产| 久久av无码专区亚洲av桃花岛| 无码人妻久久久一区二区三区| 亚洲伊人久久精品影院| 亚洲狠狠婷婷综合久久蜜芽 | 94久久国产乱子伦精品免费| 波多野结衣中文字幕久久|