The invention provides a method for deriving functions and classes and a device, a terminal and a computer readable storage medium, in which the methods for deriving functions and classes include: adding class functions for classes to be derived according to the obtained export instructions; calling C functions to call corresponding functions to be derived through any of the classes functions; and fetching out the corresponding functions to be derived from the classes. The pointer of the class to be exported is described so as to cause the member of the class to be exported to have a position offset; after the member has a position offset, the pointer of the member is taken out; and the result of taking out the pointer of the class to be exported and the pointer of the member is converted into the target data class for Lua to carry out the target data class. Export. The technical scheme of the invention can greatly reduce the number of lines of code, thereby reducing the volume of the compiled code, reducing the labor cost, reducing the error rate and improving the overall accuracy of the coding.
【技术实现步骤摘要】
函数和类的导出方法及装置、终端和计算机可读存储介质
本专利技术涉及计算机
,尤其涉及一种函数和类的导出方法及装置、终端和计算机可读存储介质。
技术介绍
目前,以cocos2dx为基础开发的游戏中,越来越多地使用lua来进行开发,使用lua开发可以解决更多的线上问题,同时也便于提升开发效率,那么将C里面的函数及数据转移到lua之中则是该项的重中之重。cocos2dx自带的lua导出机制,是将所需要导出的类及函数均单独导出,并提供给lua使用,即cc.Marquee:creat,这种方案的明显优势是使用较为方便。然而,这种方案只提供了函数的接口,但是并未提供类型里面数据的接口,并且,函数体积大,对于C++代码量级比较多,会占用大量的包体大小。因此,如何解决现有的lua导出机制的弊端,成为目前亟待解决的技术问题。
技术实现思路
本专利技术实施例提供了一种函数和类的导出方法及装置、终端和计算机可读存储介质,旨在解决如何现有的lua导出机制的弊端,能够提升lua导出机制的效率。第一方面,本专利技术实施例提供了一种函数和类的导出方法,包括:根据获取到的导出指令, ...
【技术保护点】
1.一种函数和类的导出方法,其特征在于,包括:根据获取到的导出指令,为待导出的类添加类函数;调用C函数通过任一所述类函数调用对应的待导出函数;取出所述待导出的类的指针,以使所述待导出的类的成员发生位置偏移;在所述成员发生位置偏移后,取出所述成员的指针;将取出所述待导出的类的指针和所述成员的指针后的结果转化成目标数据类,以供lua对所述目标数据类进行导出。
【技术特征摘要】
1.一种函数和类的导出方法,其特征在于,包括:根据获取到的导出指令,为待导出的类添加类函数;调用C函数通过任一所述类函数调用对应的待导出函数;取出所述待导出的类的指针,以使所述待导出的类的成员发生位置偏移;在所述成员发生位置偏移后,取出所述成员的指针;将取出所述待导出的类的指针和所述成员的指针后的结果转化成目标数据类,以供lua对所述目标数据类进行导出。2.根据权利要求1所述的方法,其特征在于,所述类函数包括luaCall函数、setProperty函数和getProperty函数。3.根据权利要求1所述的方法,其特征在于,所述调用C函数通过任一所述类函数调用对应的待导出函数的步骤,包括:调用C函数通过类:函数属性的方式进行函数调用,其中,所述函数调用的方式包括luaCallStatic调用方式和luaCall调用方式。4.根据权利要求3所述的方法,其特征在于,所述函数属性包括函数名和参数。5.一种函数和类的导出装置,其特征在于,包括:类函数添加单元,根据获取到的导出指令,为待导出的类添加类函数;函数导出单元,调用C函数通过任一所述类函数调用对应的待导出函数;第一处理单元...
【专利技术属性】
技术研发人员:张涛,
申请(专利权)人:北京智明星通科技股份有限公司,
类型:发明
国别省市:北京,11
还没有人留言评论。发表了对其他浏览者有用的留言会获得科技券。