• <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++ 技術中心

               :: 首頁 :: 聯系 ::  :: 管理
              160 Posts :: 0 Stories :: 87 Comments :: 0 Trackbacks

            公告

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

            留言簿(27)

            搜索

            •  

            最新隨筆

            最新評論

            評論排行榜

            1.下載swig,我這里用的是swigwin-2.0.9.zip,官網地址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文件,內容如下:
            %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"
            并且導入庫
            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( "測試腳本是否被調用" );
            print( "hello" );
            print( "hello, tpf" );
            print( "看到hello的字樣,表示腳本被調用" );

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

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

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

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

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

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

            10.得出結果如下:
            測試腳本是否被調用
            hello
            hello, tpf
            看到hello的字樣,表示腳本被調用
            -----------------------------
            下面測試函數
            3
            看到數字表示函數正常被調用
            -----------------------------
            下面測試類調用
            -----------------------------
            成員變量>>>     10
            成員變量>>>     20
            下面測試成員函數
            10 20
            看到數字表示成員函數被正常調用
            posted on 2014-04-24 16:12 C++技術中心 閱讀(3350) 評論(0)  編輯 收藏 引用 所屬分類: 其他編程
            伊人久久成人成综合网222| 人人狠狠综合88综合久久| 久久精品国产亚洲AV久| 久久久国产亚洲精品| 久久精品人人做人人妻人人玩| av无码久久久久不卡免费网站| 国产免费久久精品丫丫| 香港aa三级久久三级老师2021国产三级精品三级在 | 99久久国产精品免费一区二区| 无码8090精品久久一区| 国产三级久久久精品麻豆三级 | 99精品国产综合久久久久五月天| 久久久久久国产精品免费无码 | 久久一本综合| 成人资源影音先锋久久资源网| 久久99精品久久久久久不卡| 亚洲伊人久久大香线蕉综合图片 | 99热成人精品热久久669| 久久高潮一级毛片免费| 久久Av无码精品人妻系列| 嫩草影院久久国产精品| 性欧美大战久久久久久久久| 久久强奷乱码老熟女| 久久亚洲精品视频| 性色欲网站人妻丰满中文久久不卡| 久久99精品久久久久久水蜜桃| 国产午夜福利精品久久2021| 国产免费久久精品99re丫y| 精品久久久久久99人妻| 久久久久久久综合日本亚洲| 久久婷婷五月综合97色| 2021最新久久久视精品爱 | 国产亚洲精久久久久久无码| 久久精品中文无码资源站| 亚洲精品成人久久久| 久久人人爽人人爽人人片AV麻豆| 91性高湖久久久久| 久久精品无码av| 伊人久久大香线蕉精品不卡| 免费精品国产日韩热久久| 久久夜色精品国产亚洲av|