• <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++博客 :: 首頁 :: 聯系 :: 聚合  :: 管理
              57 Posts :: 2 Stories :: 57 Comments :: 0 Trackbacks

            常用鏈接

            留言簿(10)

            我參與的團隊

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            lua 的包裝庫好多 巨形的就算是luabind 因為要加boost  boost里的mpl 模板元編程 還真TMD封裝嚇死人

            這里轉載了一下這個高手的 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...

            // 這個里面一共有X個示例調用luabind注冊C++的Function && class to lua

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

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

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

            private:
            int m_number;
            };

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

            //一個模板的模板類
            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++的東西到lua里去都是用lua::module lua::def 的
            //關鍵看的就是這個 module def的寫法
            //注冊函數:luabind::module(L) [ luabind::def("print_hello", print_hello)];
            // 估計是注冊了一個lua函數
            //注冊類 :luabind::module(L) [luabind::class_<NumberPrinter>("NumberPrinter") .def(luabind::constructor<int>()).def("print", &NumberPrinter::print)];
            // 估計是

            int main() {

            //初創建一個lua_state
            lua_State *myLuaState = lua_open();

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

            //2//注冊C++函數到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 閱讀(1461) 評論(0)  編輯 收藏 引用 所屬分類: lua
            潮喷大喷水系列无码久久精品| 久久线看观看精品香蕉国产| 亚洲伊人久久成综合人影院 | 国产精品亚洲综合久久| 国产精品中文久久久久久久| 久久精品国产亚洲av影院| 久久精品人人做人人爽电影| 热久久最新网站获取| 亚洲综合精品香蕉久久网97| 日本亚洲色大成网站WWW久久| 人妻无码αv中文字幕久久| 国产成人精品久久一区二区三区av | 久久综合给久久狠狠97色| 丁香久久婷婷国产午夜视频| 99久久国产精品免费一区二区| 精品国产福利久久久| 婷婷五月深深久久精品| 欧美午夜A∨大片久久 | 天天综合久久久网| 中文无码久久精品| 欧美日韩精品久久久久| 国产成人精品久久一区二区三区av| 无码人妻少妇久久中文字幕蜜桃| 久久精品国产一区二区三区| 狠狠色丁香久久综合婷婷| 日日噜噜夜夜狠狠久久丁香五月 | 久久精品水蜜桃av综合天堂 | 久久久久99这里有精品10| 国产成人精品久久亚洲高清不卡 国产成人精品久久亚洲高清不卡 国产成人精品久久亚洲 | 国产精品视频久久久| 77777亚洲午夜久久多人| 日韩亚洲国产综合久久久| 久久99精品国产99久久6| 2021国产成人精品久久| 久久亚洲国产精品一区二区| 婷婷久久香蕉五月综合加勒比| 性欧美大战久久久久久久久| 奇米综合四色77777久久| 精品无码久久久久久午夜| 99国产欧美久久久精品蜜芽| 国产精品久久久久久久久|