• <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>

               C++ 技術(shù)中心

               :: 首頁 :: 聯(lián)系 ::  :: 管理
              160 Posts :: 0 Stories :: 87 Comments :: 0 Trackbacks

            公告

            鄭重聲明:本BLOG所發(fā)表的原創(chuàng)文章,作者保留一切權(quán)利。必須經(jīng)過作者本人同意后方可轉(zhuǎn)載,并注名作者(天空)和出處(CppBlog.com)。作者Email:coder@luckcoder.com

            留言簿(27)

            搜索

            •  

            最新隨筆

            最新評(píng)論

            評(píng)論排行榜

            1.下載swig,我這里用的是swigwin-2.0.9.zip,官網(wǎng)地址http://www.swig.org/ 載解壓后,目錄下有swig.exe程序
            2. 在VS中新建工程TestLua
            3.添加hello.h代碼如下:
            #ifndef HELLO_H__
            #define HELLO_H__

            int sum( int a, int b );
            class Test
            {
            public:
                int a;
                int b;
                Test();
                void print();
            };

            #endif/*HELLO_H__*/

            4.添加hello.cpp代碼如下:
            #include "stdafx.h"
            #include "hello.h"

            int sum( int a, int b )
            {
                return (a + b);
            }
            Test::Test()
            {
                a = 10;
                b = 20;
            }
            void Test::print()
            {
                printf( "%d %d\n", a, b );
            }

            5.編寫modulehello.i文件,內(nèi)容如下:
            %module hello
            %{
            #include "hello.h"
            %}
            %include "hello.h"

            6.使用以下命令生成文件
            swig.exe -c++ -lua c:\modulehello.i
            于是生成:modulehello_wrap.cxx文件

            7.在工程包含
            C:\Program Files (x86)\Lua\5.1\include
            符加庫目錄"C:\Program Files (x86)\Lua\5.1\lib"
            并且導(dǎo)入庫
            lua51.lib

            8.在工程文件TestLua.cpp代碼如下:
            #include "stdafx.h"
            extern "C"
            {
            #include <lua.h>
            #include <lualib.h>
            #include <lauxlib.h>
            };
            #include "modulehello_wrap.cxx"
            extern "C"
            {
                extern int luaopen_hello(lua_State* L); // declare the wrapped module
            };
            int _tmain(int argc, _TCHAR* argv[])
            {
                lua_State *L;
                L=lua_open();
                luaopen_base(L);    // load basic libs (eg. print)
                luaopen_hello(L);    // load the wrappered module
                if (luaL_loadfile(L,"./hello.lua")==0) // load and run the file
                    lua_pcall(L,0,0,0);
                else
                    printf("unable to load %s\n","hello.lua");
                lua_close(L);

                return 0;
            }

            9.編寫lua腳本hello.lua如下:
            print( "測試腳本是否被調(diào)用" );
            print( "hello" );
            print( "hello, tpf" );
            print( "看到hello的字樣,表示腳本被調(diào)用" );

            print( "-----------------------------" );

            print( "下面測試函數(shù)" );
            print( hello.sum( 1, 2 ) );
            print( "看到數(shù)字表示函數(shù)正常被調(diào)用" );

            print( "-----------------------------" );

            print( "下面測試類調(diào)用" );
            a = hello.Test();

            print( "-----------------------------" );
            print( "成員變量>>>", a.a );
            print( "成員變量>>>", a.b );

            print( "下面測試成員函數(shù)" );
            a:print();
            print( "看到數(shù)字表示成員函數(shù)被正常調(diào)用" );

            10.得出結(jié)果如下:
            測試腳本是否被調(diào)用
            hello
            hello, tpf
            看到hello的字樣,表示腳本被調(diào)用
            -----------------------------
            下面測試函數(shù)
            3
            看到數(shù)字表示函數(shù)正常被調(diào)用
            -----------------------------
            下面測試類調(diào)用
            -----------------------------
            成員變量>>>     10
            成員變量>>>     20
            下面測試成員函數(shù)
            10 20
            看到數(shù)字表示成員函數(shù)被正常調(diào)用
            posted on 2014-04-24 16:12 C++技術(shù)中心 閱讀(3338) 評(píng)論(0)  編輯 收藏 引用 所屬分類: 其他編程
            久久天天躁狠狠躁夜夜2020| 欧洲性大片xxxxx久久久| 亚洲中文字幕无码久久综合网| 久久久久99精品成人片三人毛片| 精品久久久久久成人AV| 国产成年无码久久久久毛片| 久久久久国产精品人妻| 久久国产精品一国产精品金尊| 久久精品一本到99热免费| 一本久久知道综合久久| 97精品国产97久久久久久免费| 久久99精品国产麻豆宅宅| 亚洲精品乱码久久久久久中文字幕| 久久99精品久久久久久久不卡| 99蜜桃臀久久久欧美精品网站| 亚洲精品美女久久777777| 久久久久99精品成人片试看| 国产精品久久久久久搜索| 久久亚洲AV无码西西人体| 亚洲性久久久影院| 久久九九亚洲精品| 囯产极品美女高潮无套久久久| 日韩人妻无码精品久久久不卡 | 久久91精品国产91久久小草| 国产精品成人精品久久久| 亚洲精品白浆高清久久久久久| 国产三级久久久精品麻豆三级| 国产精品久久久久久一区二区三区| 91秦先生久久久久久久| 精品无码久久久久久尤物| 久久国产精品久久| 思思久久好好热精品国产| 久久亚洲天堂| 久久婷婷五月综合国产尤物app | 久久久国产精华液| 精品国产乱码久久久久久1区2区| 精品久久久久久国产免费了| 精品熟女少妇av免费久久| 精品久久人人做人人爽综合| 亚洲级αV无码毛片久久精品| 女人香蕉久久**毛片精品|