ELuna 注册 Lua 绑定

使用的 https://github.com/radiotail/eluna 提供的头文件,可注册类和函数,这个头文件提供了一个垃圾收集器,用来把绑定过的对象释放掉,那个循环释放写的有点问题。

原始

struct CPPGarbage

{

inline static void pushMethod(GenericMethod* method) { m_CPPMethods.push_back(method);};

inline static void pushFunction(GenericFunction* function) { m_CPPFunctions.push_back(function);};

inline static void release() {

for (Function_Vector::iterator itr = m_CPPFunctions.begin(); itr != m_CPPFunctions.end(); ++itr) {

delete *itr;

}

for (Method_Vector::iterator itr = m_CPPMethods.begin(); itr != m_CPPMethods.end(); ++itr) {

delete *itr;

}

}

private:

static Function_Vector m_CPPFunctions;

static Method_Vector m_CPPMethods;

};

Function_Vector CPPGarbage::m_CPPFunctions;

Method_Vector CPPGarbage::m_CPPMethods;

改为

struct CPPGarbage
    {
        inline static void pushMethod(GenericMethod* method) { m_CPPMethods.push_back(method);};
        inline static void pushFunction(GenericFunction* function) { m_CPPFunctions.push_back(function);};

        inline static void release() {
            for (Function_Vector::iterator itr = m_CPPFunctions.begin(); itr != m_CPPFunctions.end(); ++itr) {
                if (*itr) {
                    delete *itr;
                    *itr = NULL;
                }
            }

            for (Method_Vector::iterator itr = m_CPPMethods.begin(); itr != m_CPPMethods.end(); ++itr) {
                if (*itr) {
                    delete *itr;
                    *itr = NULL;
                }
            }
        }
    private:
        static Function_Vector m_CPPFunctions;
        static Method_Vector   m_CPPMethods;
    };
    //Function_Vector CPPGarbage::m_CPPFunctions;
    //Method_Vector   CPPGarbage::m_CPPMethods;
    __declspec(selectany) Function_Vector CPPGarbage::m_CPPFunctions;

    __declspec(selectany) Method_Vector   CPPGarbage::m_CPPMethods;
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 136,092评论 19 139
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 176,235评论 25 709
  • 【其实我忽然感觉自己掉进了一个大坑……】 群里有个小伙伴在德国,正好问到要不要代购点什么东西回国,一番思考之后手贱...
    周潇洒阅读 9,607评论 6 3
  • 今年开始,陆续开始自己在家做早餐,早起半小时,为自己准备一份可口的早餐,让一天的开始变得更清新更美好,不能说...
    思研思语阅读 1,634评论 0 0

友情链接更多精彩内容