WO2017028720A1 - 对象传递方法和装置 - Google Patents
对象传递方法和装置 Download PDFInfo
- Publication number
- WO2017028720A1 WO2017028720A1 PCT/CN2016/094321 CN2016094321W WO2017028720A1 WO 2017028720 A1 WO2017028720 A1 WO 2017028720A1 CN 2016094321 W CN2016094321 W CN 2016094321W WO 2017028720 A1 WO2017028720 A1 WO 2017028720A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- script
- constructor
- program
- host
- thread
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Ceased
Links
Images
Definitions
- the present application belongs to the field of computer technology, and in particular, to an object delivery method and apparatus.
- the host program interacts with the script program and the host program passes the object to the script program and triggers the execution of the script program, if the host language is different from the script language, how the object is represented is a major problem faced by the host program and the script program.
- Objects are programming content used to represent specific things, abstract rules, plans, or times in object-oriented programming.
- the host program expands one or more script language types as needed, and uses these types to instantiate the object of the script language and pass it to the script program.
- the method according to the prior art is that the creation of the object is performed in the host thread of the host program, and the access of the object is performed in the script thread of the script program.
- some scripting languages do not support multi-threaded behavior, operations on the same context are required to be performed on the same thread, such as the scripting language Lua. Therefore, the existing method is less versatile and cannot be supported by all scripting languages.
- the technical problem to be solved by the present application is to provide an object delivery method and apparatus, which improves the versatility of the object delivery method.
- an object delivery method including:
- the host program in the host thread interacts with the script program in the script thread, the host program acquires the constructor of the object and the original data;
- the scripter Passing the constructor of the object and the raw data to the script program, the scripter invoking the constructor on the script thread to create the object based on the raw data.
- the transferring the constructor of the object and the original data to the script program comprises:
- the transferring the constructor of the object and the original data to the script program comprises:
- the constructor of the object and the raw data are packaged into closures and passed to the script.
- the method further includes:
- the passing the constructor of the object and the raw data to the script program includes:
- An object delivery method includes:
- the script program acquires the constructor and the original data passed by the host program;
- the constructor is called on a script thread to create the object based on the raw data.
- An object delivery device comprising:
- An obtaining module configured to acquire a constructor of the object and raw data when the host program in the host thread interacts with the script program in the script thread; wherein the host thread is different from the script thread;
- a delivery module for passing the constructor of the object and the raw data to the script program, the script program calling the constructor on the script thread to create the object according to the original data.
- the delivery module comprises:
- a conversion unit configured to convert the constructor into a constructor of the script language type according to a script language type of the script program
- a transfer unit configured to pass the converted constructor and the original data to the script program.
- the delivery module is specifically configured to package the constructor of the object and the original data into a closure and deliver to the script program.
- the method further comprises:
- the delivery module is specifically configured to pass the constructor of the object and the original data to the script program through the delivery queue.
- An object delivery device comprising:
- a receiving module configured to: when the host program in the host thread interacts with the script program in the script thread, the script program acquires the constructor and the original data passed by the host program;
- the host program passes the object's constructor and raw data to the script program, and the script program creates the object in the script thread, so that the object creation and access are in the same thread, which can be applied to different scripting languages, ensuring the object delivery mode. Universality.
- FIG. 1 is a flow chart of an embodiment of an object delivery method according to an embodiment of the present application.
- FIG. 2 is a flowchart of another embodiment of an object delivery method according to an embodiment of the present application.
- FIG. 3 is a flowchart of still another embodiment of an object delivery method according to an embodiment of the present application.
- FIG. 4 is a schematic structural diagram of an embodiment of an object delivery device according to an embodiment of the present application.
- FIG. 5 is a schematic structural diagram of another embodiment of an object transfer apparatus according to an embodiment of the present application.
- FIG. 6 is a schematic structural diagram of still another embodiment of an object transfer device according to an embodiment of the present application.
- FIG. 7 is a schematic structural diagram of still another embodiment of an object transfer apparatus according to an embodiment of the present application.
- a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
- processors CPUs
- input/output interfaces network interfaces
- memory volatile and non-volatile memory
- the memory may include non-persistent memory, random access memory (RAM), and/or non-volatile memory in a computer readable medium, such as read only memory (ROM) or flash memory.
- RAM random access memory
- ROM read only memory
- Memory is an example of a computer readable medium.
- Computer readable media includes both permanent and non-persistent, removable and non-removable media.
- Information storage can be implemented by any method or technology.
- the information can be computer readable instructions, data structures, modules of programs, or other data.
- Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read only memory. (ROM), electrically erasable programmable read only memory (EEPROM), flash memory or other memory technology, compact disk read only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, Magnetic tape cartridges, magnetic tape storage or other magnetic storage devices or any other non-transportable media can be used to store information that can be accessed by a computing device.
- computer readable media does not include non-transitory computer readable media, such as modulated data signals and carrier waves.
- FIG. 1 is a flowchart of an embodiment of an object delivery method according to an embodiment of the present application. The method may include the following steps:
- a script is a program code. It is a program code that is provided by a system (such as an operating system) or a server (such as a Web Server) or an application (such as AutoCAD, MSOffice, etc.), that is, a host program.
- a system such as an operating system
- a server such as a Web Server
- an application such as AutoCAD, MSOffice, etc.
- An instruction execution sequence that automates the functions of the environment.
- the software environment on which the script depends to survive is called the host.
- the host program can be the operating system, the server program, the application program, and the programming language for developing these host programs (for example, the development operating system generally uses the C language, and the development Web Server generally uses C language or Java language, and development applications generally use C++/Java/c# language) is called Host Language.
- the interaction between the host program and the script program is usually involved.
- the host program passes the object to the script program in one direction and triggers the execution of the script program.
- the host program when the host program interacts with the script program, the host program transfers the constructor and the original data of the acquired object to the script program, and the script program calls the constructor to create the object according to the original data, thereby implementing the object. Pass. Make the creation and access of the object are executed by the script program, even if the host program and the script program are in different threads, the object creation and access are guaranteed to be in the same thread, so it can be applied to different
- the scripting language can be supported by different scripting languages, ensuring the versatility of object delivery methods.
- the original data refers to data of a construction object
- an object of a script language is created according to the original data
- scripting languages such as javascript, Lua, VBscript, etc.
- a possible implementation manner requires the user to provide a scripting language for creating a corresponding scripting program.
- the constructor of the type since there are many types of scripting languages, such as javascript, Lua, VBscript, etc., in order to be able to create an object of the scripting language type of the scripting program, a possible implementation manner requires the user to provide a scripting language for creating a corresponding scripting program.
- the constructor of the type is a scripting language for creating a corresponding scripting program.
- the user-provided constructor can be a constructor of a particular scripting language type, or a constructor described in a pre-defined abstract description.
- the constructor is converted according to the script language type of the script program of the interaction, so that the script program can be called.
- FIG. 2 it is a flowchart of another embodiment of an object delivery method provided by an embodiment of the present application, where the method may include the following steps:
- 201 When a host program in a host thread interacts with a script program in a script thread, the host program acquires a constructor of the object and raw data.
- the host thread may be the same as or different from the script thread.
- the constructor When the user-provided constructor is described by a preset abstract description manner, the constructor is converted into a constructor of the script language type, and may be described according to a preset abstract description manner and a script language of different script language types. The corresponding relationship of the mode, the constructor is converted, and converted into a constructor of the script language type of the script program.
- NewObject() creates an empty object and returns
- SetIntegerField(o, name, i) sets the name field of the specified object o to an integer i
- SetFloatField(o,name,f) sets the name field of the specified object o to a floating point number f
- SetStringField(o,name,s) sets the name field of the object o to the string s
- SetObjectField(o, name, o1) sets the name field of the object o to the object o1
- the mapping relationship between different types of scripting languages may be set according to a preset manner. Convert the constructor.
- the user does not need to provide a constructor function of different script language types, and only needs to provide a preset description manner, that is, a constructor that can be automatically converted into a different script language type, which reduces the number of constructors. the complexity.
- the producer-consumer queue can be created between the host program and the script program, that is, the delivery queue, so that the host program can pass the constructor and the original data to the script program through the delivery queue.
- the delivery queue uses a first-in, first-out approach.
- the constructor and the original data can be packaged into a closure.
- the closure is passed to the script program, and the closure can be passed to the script program through the delivery queue.
- FIG. 3 is a flowchart of still another embodiment of an object delivery method according to an embodiment of the present application. The method may include the following steps:
- the host thread and the script thread may be different or the same.
- the constructor and the original data can be packaged as a closure and passed as a closure.
- a delivery queue can be created between the host program and the script program to obtain the constructor and raw data passed by the host program through the delivery queue.
- the job that called the constructor can also be used to return the created object to the upper level of the script, which is executed by the upper layer of the script.
- the host program when the host program interacts with the script program, the host program transfers the constructor and the original data of the acquired object to the script program, and the script program calls the constructor to generate the object according to the original data. That is to say, the creation and access of the object are executed by the script program. Even if the host program and the script program are in different threads, the creation and access of the object are guaranteed to be in the same thread, so it can be applied to different scripting languages and the object is guaranteed.
- the versatility of the delivery method when the host program interacts with the script program, the host program transfers the constructor and the original data of the acquired object to the script program, and the script program calls the constructor to generate the object according to the original data. That is to say, the creation and access of the object are executed by the script program. Even if the host program and the script program are in different threads, the creation and access of the object are guaranteed to be in the same thread, so it can be applied to different scripting languages and the object is guaranteed.
- the versatility of the delivery method is
- the embodiment of the present application further provides an object transfer device, as shown in FIG. 4 , which is a schematic structural diagram of an embodiment of an object transfer device according to an embodiment of the present application.
- the device may include:
- the obtaining module 401 is configured to acquire the constructor of the object and the original data when the host program in the host thread interacts with the script program in the script thread.
- the delivery module 402 is configured to pass the constructor of the object and the original data to the script program, and the script program invokes the constructor on the script thread to create the object according to the original data.
- the host thread may be the same as or different from the script thread.
- the constructor of the acquired object and the original data are passed to the script program, and the constructor is called by the script program to create the object according to the original data, thereby realizing the object transfer. That is to say, the creation and access of the object are executed by the script program. Even if the host program and the script program are in different threads, the creation and access of the object are guaranteed to be in the same thread, so it can be applied to different scripting languages to ensure object delivery.
- the object delivery device in this embodiment is specifically applied to a host program.
- the delivery module 402 can include:
- the converting unit 501 is configured to convert the constructor into a constructor of the script language type according to a scripting language of the script program;
- the delivery unit 502 is configured to pass the converted constructor and the original data to the script program.
- the producer-consumer queue can be created between the host program and the script program, that is, the delivery queue, so that the host program can pass the constructor and the original data to the script program through the delivery queue.
- the delivery queue uses a first-in, first-out approach.
- the apparatus may further include:
- the establishing module 403 is configured to establish a delivery queue between the host program and the script program;
- the delivery module 402 is specifically configured to pass the constructor of the object and the original data to the script program through the delivery queue.
- the delivery unit is specifically configured to pass the constructor of the object and the original data to the script program through the delivery queue.
- the constructor and the original data may be packaged into a closure. Therefore, the delivery module is specifically configured to package the constructor of the object and the original data into a closure, and transmit the template to the script program. The closure is passed to the script through the delivery queue.
- FIG. 7 is a schematic structural diagram of another embodiment of an object delivery apparatus according to an embodiment of the present application.
- the apparatus of this embodiment is specifically applied to a script program, and the apparatus may include:
- the receiving module 701 is configured to: when the host program in the host thread interacts with the script program in the script thread, the script program acquires the constructor and the original data passed by the host program;
- a creation module 702 is configured to invoke the constructor on a script thread to create the object based on the raw data.
- the host thread and the script thread may be different or the same.
- the constructor and the original data can be packaged as a closure and passed as a closure.
- a delivery queue can be created between the host program and the script program to obtain the constructor and raw data passed by the host program through the delivery queue.
- the job that called the constructor can also be used to return the created object to the upper level of the script, which is executed by the upper layer of the script.
- the host program when the host program interacts with the script program, the host program transfers the constructor and the original data of the acquired object to the script program, and the script program calls the constructor to create the object according to the original data. That is to say, the creation and access of the object are executed by the script program. Even if the host program and the script program are in different threads, the creation and access of the object are guaranteed to be in the same thread, so it can be applied to different scripting languages to ensure object delivery.
- the host language is C++
- the scripting language is Lua
- the object to be passed is Student (student), which contains two attributes: student number (id, integer data) and name (name, string data).
- student number id, integer data
- name name, string data
- the builder is included in the library provided by the host program.
- the constructor and the object's raw data are marked as a closure, and then the closure is pushed into the queue of the delivery object.
- the purpose of the closure is to "bind" the constructor with the original data of the object; the closure is also an extension of the scripting language, which can be called once in the scripting language. The process used to perform the construction and return the created object.
- the host program passes the constructor and the raw data.
- the execution of the script creation object can be implemented as follows:
- first device can be directly electrically coupled to the second device, or electrically coupled indirectly through other devices or coupling means. Connect To the second device.
Landscapes
- Stored Programmes (AREA)
- Devices For Executing Special Programs (AREA)
Abstract
一种对象传递方法和装置,所述方法包括:宿主线程中的宿主程序与脚本线程中的脚本程序交互时,所述宿主程序获取所述对象的构造函数以及原始数据(101);将所述对象的构造函数以及所述原始数据传递至所述脚本程序,由所述脚本程序在所述脚本线程上调用所述构造函数,根据所述原始数据创建所述对象(102)。上述方法具有通用性,适用于不同的脚本语言。
Description
本申请要求2015年08月19日递交的申请号为201510512106.4、发明名称为“对象传递方法和装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
本申请属于计算机技术领域,具体地说,涉及对象传递方法和装置。
在宿主程序与脚本程序交互,宿主程序传递对象给脚本程序,触发脚本程序执行的应用环境中,若宿主语言与脚本语言不同,对象如何表示成为宿主程序与脚本程序交互面临的主要问题。
对象是指在面向对象的程序设计中,用来表示具体的事物、抽象的规则、计划或时间等的编程内容。
现有技术的一种对象传递方法中,由宿主程序根据需要扩展一种或多种脚本语言类型,并用这些类型实例化出脚本语言的对象,传递给脚本程序。
但是,若宿主程序和脚本程序在不同线程中运行,按照现有技术的这种方式也即是对象的创建在宿主程序的宿主线程中进行,而对象的访问是在脚本程序的脚本线程进行,但是由于某些脚本语言不支持多线程行为,要求针对同一上下文的操作都是在同一线程上进行,比如脚本语言Lua语言。因此采用现有的这种方式通用性较差,不能被所有的脚本语言所支持。
发明内容
有鉴于此,本申请所要解决的技术问题是提供了一种对象传递方法和装置,提高了对象传递方式的通用性。
为了解决上述技术问题,本申请公开了一种对象传递方法,包括:
宿主线程中的宿主程序与脚本线程中的脚本程序交互时,所述宿主程序获取所述对象的构造函数以及原始数据;
将所述对象的构造函数以及所述原始数据传递至所述脚本程序,由所述脚本程序在所述脚本线程上调用所述构造函数,根据所述原始数据创建所述对象。
优选地,所述将所述对象的构造函数以及原始数据传递至所述脚本程序包括:
根据所述脚本程序的脚本语言类型,将所述构造函数转换为所述脚本语言类型的构造函数;
将转换之后的构造函数以及所述原始数据传递至所述脚本程序。
优选地,所述将所述对象的构造函数以及原始数据传递至所述脚本程序包括:
将所述对象的构造函数以及原始数据打包成闭包,传递至所述脚本程序。
优选地,将所述对象的构造函数以及原始数据传递至所述脚本程序之前,所述方法还包括:
建立宿主程序与脚本程序之间的传递队列;
所述将所述对象的构造函数以及原始数据传递至所述脚本程序包括:
将所述对象的构造函数以及原始数据通过所述传递队列传递至所述脚本程序。
一种对象传递方法,包括:
在宿主线程中的宿主程序与脚本线程中的脚本程序交互时,所述脚本程序获取所述宿主程序传递的构造函数以及原始数据;
在脚本线程上调用所述构造函数,根据所述原始数据创建所述对象。
一种对象传递装置,包括:
获取模块,用于在宿主线程中的宿主程序与脚本线程中的脚本程序交互时,获取所述对象的构造函数以及原始数据;其中,所述宿主线程与所述脚本线程不同;
传递模块,用于将所述对象的构造函数以及原始数据传递至所述脚本程序,由所述脚本程序在所述脚本线程上调用所述构造函数,根据所述原始数据创建所述对象。
优选地,所述传递模块包括:
转换单元,用于根据所述脚本程序的脚本语言类型,将所述构造函数转换为所述脚本语言类型的构造函数;
传递单元,用于将转换之后的构造函数以及所述原始数据传递至所述脚本程序。
优选地,所述传递模块具体用于将所述对象的构造函数以及原始数据打包成闭包,传递至所述脚本程序。
优选地,还包括:
建立模块,用于建立宿主程序与脚本程序之间的传递队列;
所述传递模块具体用于将所述对象的构造函数以及原始数据通过所述传递队列传递至所述脚本程序。
一种对象传递装置,包括:
接收模块,用于在宿主线程中的宿主程序与脚本线程中的脚本程序交互时,所述脚本程序获取所述宿主程序传递的构造函数以及原始数据;
创建模块,用于在脚本线程上调用所述构造函数,根据所述原始数据创建所述对象。
与现有技术相比,本申请可以获得包括以下技术效果:
宿主程序将对象的构造函数以及原始数据传递至脚本程序,由脚本程序在脚本线程中创建对象,使得对象的创建和访问均在同一个线程,可以适用于不同的脚本语言,保证了对象传递方式的通用性。
当然,实施本申请的任一产品必不一定需要同时达到以上所述的所有技术效果。
此处所说明的附图用来提供对本申请的进一步理解,构成本申请的一部分,本申请的示意性实施例及其说明用于解释本申请,并不构成对本申请的不当限定。在附图中:
图1是本申请实施例的一种对象传递方法一个实施例的流程图;
图2是本申请实施例的一种对象传递方法另一个实施例的流程图;
图3是本申请实施例的一种对象传递方法又一个实施例的流程图;
图4是本申请实施例的一种对象传递装置一个实施例的结构示意图;
图5是本申请实施例的一种对象传递装置另一个实施例的结构示意图;
图6是本申请实施例的一种对象传递装置又一个实施例的结构示意图;
图7是本申请实施例的一种对象传递装置又一个实施例的结构示意图。
以下将配合附图及实施例来详细说明本申请的实施方式,藉此对本申请如何应用技术手段来解决技术问题并达成技术功效的实现过程能充分理解并据以实施。
在一个典型的配置中,计算设备包括一个或多个处理器(CPU)、输入/输出接口、网络接口和内存。
内存可能包括计算机可读介质中的非永久性存储器,随机存取存储器(RAM)和/或非易失性内存等形式,如只读存储器(ROM)或闪存(flash RAM)。内存是计算机可读介质的示例。
计算机可读介质包括永久性和非永久性、可移动和非可移动媒体可以由任何方法或技术来实现信息存储。信息可以是计算机可读指令、数据结构、程序的模块或其他数据。
计算机的存储介质的例子包括,但不限于相变内存(PRAM)、静态随机存取存储器(SRAM)、动态随机存取存储器(DRAM)、其他类型的随机存取存储器(RAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、快闪记忆体或其他内存技术、只读光盘只读存储器(CD-ROM)、数字多功能光盘(DVD)或其他光学存储、磁盒式磁带,磁带磁磁盘存储或其他磁性存储设备或任何其他非传输介质,可用于存储可以被计算设备访问的信息。按照本文中的界定,计算机可读介质不包括非暂存电脑可读媒体(transitory media),如调制的数据信号和载波。
图1为本申请实施例提供的一种对象传递方法一个实施例的流程图,该方法可以包括以下几个步骤:
101:宿主线程中的宿主程序与脚本线程中的脚本程序交互时,所述宿主程序获取所述对象的构造函数以及原始数据。
102:将所述对象的构造函数以及原始数据传递至所述脚本程序,由所述脚本程序在所述脚本线程上调用所述构造函数,根据所述原始数据生成所述对象。
脚本程序简称脚本(Script),是一种程序代码,它是由某个系统(如操作系统)或服务器(如Web Server)或应用程序(如AutoCAD,MSOffice等)环境,即宿主程序提供的能自动化操作该环境的功能的指令执行序列。
而为了合法地编写出脚本程序所制定的形式语法和语义的规范,原则,定义等等,形成了脚本语言(Scripting Language)。
脚本程序赖以生存的软件环境被称作是宿主程序(host),宿主程序可以是操作系统,服务器程序,应用程序,而开发这些宿主程序的程序语言(如开发操作系统一般使用c语言,开发Web Server一般使用c语言或Java语言,开发应用程序一般使用C++/Java/c#语言)被称作宿主语言(Host Language)。
由于宿主语言比较复杂,为了能够满足不同用户的需求,推出了比较简洁、方便的脚本语言供用户使用。
而在嵌入执行脚本语言的宿主语言的产品中,通常就会涉及到宿主程序和脚本程序的交互,在交互过程中,宿主程序要单向传递对象给脚本程序,触发脚本程序执行。
本申请实施例中,宿主程序与脚本程序交互时,宿主程序将获取的对象的构造函数以及原始数据传递至脚本程序,由脚本程序调用构造函数,根据原始数据创建所述对象,从而实现了对象的传递。使得对象的创建和访问均由脚本程序执行,即便宿主程序与脚本程序在不同线程中,也保证了对象的创建和访问在同一个线程,因此可以适用于不同
的脚本语言,能够被不同的脚本语言支持,保证了对象传递方式的通用性。
其中,本申请实施例中,原始数据是指构造对象的数据,构造函数用于被调用时,根据所述原始数据创建脚本语言的对象。
原始数据和构造函数均为用户提供的。
而由于脚本语言存在多种类型,比如javascript、Lua、VBscript等,为了能够创造出所述脚本程序的脚本语言类型的对象,一种可能的实现方式,需要由用户提供创建对应脚本程序的脚本语言类型的构造函数。
为了降低复杂度,作为又一个实施例,用户提供的构造函数可以是某一种特定脚本语言类型的构造函数,或者是采用预设的抽象描述方式描述的构造函数。
宿主程序获取得到用户提供的所述对象的原始数据以及构造函数之后,根据其交互的脚本程序的脚本语言类型,将构造函数进行转换,使得所述脚本程序可以调用。
如图2所述,为本申请实施例提供的对象传递方法另一个实施例的流程图,该方法可以包括以下几个步骤:
201:宿主线程中的宿主程序与脚本线程中的脚本程序交互时,所述宿主程序获取所述对象的构造函数以及原始数据。
202:根据所述脚本程序的脚本语言类型,将所述构造函数转换为所述脚本语言类型的构造函数。
203:将转换之后的构造函数以及所述原始数据传递至所述脚本程序,由所述脚本程序在所述脚本线程上调用所述构造函数,根据所述原始数据创建所述对象。
其中,所述宿主线程与所述脚本线程可以相同,也可以不同。
在用户提供的构造函数由预设的抽象描述方式描述的时,将所述构造函数转换为所述脚本语言类型的构造函数,可以根据预设的抽象描述方式与不同脚本语言类型的脚本语言描述方式的对应关系,将构造函数进行转换,转换为所述脚本程序的脚本语言类型的构造函数。
下面举例说明一种可能的预设的抽象描述方式:
NewObject()创建一个空的对象并返回
SetIntegerField(o,name,i)设置指定对象o的name域为整数i
SetFloatField(o,name,f)设置指定对象o的name域为浮点数f
SetStringField(o,name,s)设置对象o的name域为字符串s
SetObjectField(o,name,o1)设置对象o的name域为对象o1
Finish()完成对象的创建。
由于脚本语言的有多种类型,实现上述抽象描述方式中不同功能的脚本语言在此不再赘述。
在用户提供的构造函数即为采用一种特定脚本语言描述的时,若构造函数对应脚本语言类型与所述脚本程序的脚本语言类型不同,可以根据预先设置的不同类型的脚本语言的对应关系,将构造函数进行转换。
本申请实施例,通过将构造函数进行转换,使得无需用户提供不同脚本语言类型的构造函数,只需提供采用通过的预设描述方式,即可以自动转换为不同脚本语言类型的构造函数,减少了复杂度。
其中,宿主程序与脚本程序之间可以创建生产者-消费者队列,即传递队列,从而宿主程序可以通过传递队列将构造函数以及原始数据传递至脚本程序。传递队列采用先进先出方式。
其中,为了将对象的构造过程在脚本线程中执行,构造函数和原始数据可以打包成一个闭包,具体是将闭包传递至脚本程序,可以通过传递队列将闭包传递至脚本程序。
图3为本申请实施例提供的一种对象传递方法又一个实施例的流程图,该方法可以包括以下几个步骤:
301:在宿主线程中的宿主程序与脚本线程中的脚本程序交互时,所述脚本程序获取所述宿主程序传递的构造函数以及原始数据;
302:在脚本线程上调用所述构造函数,根据所述原始数据创建所述对象。
其中,所述宿主线程和所述脚本线程可以不同,也可以相同。
宿主程序传递的构造函数以及原始数据,具体是用户提供的。
其中,构造函数与原始数据可以打包为一个闭包,以闭包形式传递。
宿主程序和脚本程序之间可以创建一传递队列,通过传递队列获取宿主程序传递的构造函数以及原始数据。
通过调用构造函数创建对象之后,调用该构造函数的作业还可以用于将创建的对象返回至脚本程序的上层,由脚本程序的上层执行。
本申请实施例中,宿主程序与脚本程序交互时,宿主程序将获取的对象的构造函数以及原始数据传递至脚本程序,由脚本程序调用构造函数,根据原始数据生成所述对象。也即对象的创建和访问均由脚本程序执行,即便宿主程序与脚本程序在不同线程中,也保证了对象的创建和访问在同一个线程,因此可以适用于不同的脚本语言,保证了对象
传递方式的通用性。
本申请实施例还提供了一种对象传递装置,如图4所示,为本申请实施例提供的对象传递装置一个实施例的结构示意图该装置可以包括:
获取模块401,用于在宿主线程中的宿主程序与脚本线程中的脚本程序交互时,获取所述对象的构造函数以及原始数据。
传递模块402,用于将所述对象的构造函数以及原始数据传递至所述脚本程序,由所述脚本程序在所述脚本线程上调用所述构造函数,根据所述原始数据创建所述对象。
其中,所述宿主线程与所述脚本线程可以相同,也可以不同。
本实施例中,宿主程序与脚本程序交互时,获取的对象的构造函数以及原始数据传递至脚本程序,由脚本程序调用构造函数,根据原始数据创建所述对象,从而实现了对象的传递。也即对象的创建和访问均由脚本程序执行,即便宿主程序与脚本程序在不同线程中,也保证了对象的创建和访问在同一个线程,因此可以适用于不同的脚本语言,保证了对象传递方式的通用性。
本实施例中对象传递装置具体应用于宿主程序中。
作为另一个实施例,如图5所述,该传递模块402可以包括:
转换单元501,用于根据所述脚本程序的脚本语言,将所述构造函数转换为所述脚本语言类型的构造函数;
传递单元502,用于将转换之后的构造函数以及所述原始数据传递至所述脚本程序。
通过将构造函数进行转换,使得无需用户提供不同脚本语言类型的构造函数,只需提供采用通过的预设描述方式,即可以自动转换为不同脚本语言类型的构造函数,减少了复杂度。
其中,宿主程序与脚本程序之间可以创建生产者-消费者队列,即传递队列,从而宿主程序可以通过传递队列将构造函数以及原始数据传递至脚本程序。传递队列采用先进先出方式。
因此,如图6所述,该装置还可以包括:
建立模块403,用于建立宿主程序与脚本程序之间的传递队列;
所述传递模块402具体用于将所述对象的构造函数以及原始数据通过所述传递队列传递至所述脚本程序。
在传递模块由于转换单元和传递单元组成时,传递单元具体用于将所述对象的构造函数以及原始数据通过所述传递队列传递至所述脚本程序。
作为又一个实施例,构造函数和原始数据可以打包成一个闭包,因此,该传递模块具体是用于将所述对象的构造函数以及原始数据打包成闭包,传递至所述脚本程序,可以是通过传递队列将闭包传递至脚本程序。
图7为本申请实施例提供的一种对象传递装置又一个实施例的结构示意,本实施例的装置具体应用于脚本程序中,该装置可以包括:
接收模块701,用于在宿主线程中的宿主程序与脚本线程中的脚本程序交互时,所述脚本程序获取所述宿主程序传递的构造函数以及原始数据;
创建模块702,用于在脚本线程上调用所述构造函数,根据所述原始数据创建所述对象。
其中,所述宿主线程和所述脚本线程可以不同,也可以相同。
宿主程序传递的构造函数以及原始数据,具体是用户提供的。
其中,构造函数与原始数据可以打包为一个闭包,以闭包形式传递。
宿主程序和脚本程序之间可以创建一传递队列,通过传递队列获取宿主程序传递的构造函数以及原始数据。
通过调用构造函数创建对象之后,调用该构造函数的作业还可以用于将创建的对象返回至脚本程序的上层,由脚本程序的上层执行。
本实施例中,宿主程序与脚本程序交互时,宿主程序将获取的对象的构造函数以及原始数据传递至脚本程序,由脚本程序调用构造函数,根据原始数据创建所述对象。也即对象的创建和访问均由脚本程序执行,即便宿主程序与脚本程序在不同线程中,也保证了对象的创建和访问在同一个线程,因此可以适用于不同的脚本语言,保证了对象传递方式的通用性。
下面将结合一个实际应用场景,来对本发明的技术方案进行描述:
假设宿主语言为C++,脚本语言为Lua,待传递的对象为Student(学生),其中包含学号(id,整型数据)和姓名(name,字符串数据)两种属性。宿主语言和脚本语言各自所运行的线程已经创建好,并且用于传递对象的队列也已经准备就绪。
首先,准备构造函数,它接受学号,姓名作为原始数据,同时接受一个用于构建Lua对象的构建器(builder)。构建器包含于宿主程序提供的函数库。
采用预设的抽象描述方式的构造函数的C++代码如下:
void StudentConstructor(Builder b,int id,string name)
{
Object o=b.NewObject(); //创建一个空对象
o.SetIntegerField(“id”,id); //设置其id字段
o.SetStringField(“name”,name);//设置其name字段
b.Finish(o); //完成构建过程
}
然后,将该构造函数和对象的原始数据打成一个闭包,接着将闭包push到传递对象的队列里。在宿主语言里,闭包的作用是将构造函数和对象的原始数据“绑定”(bind)在一起;闭包同时是脚本语言的一种扩展,在脚本语言里,它能被调用一次,用于执行构造的过程,并返回创建的对象。
宿主程序传递构造函数以及原始数据,脚本程序创建对象的执行可以按照如下代码实现:
C++code:
int id=31; //原始数据:学号31
string name=“mark”; //原始数据:姓名mark
Closure c=bind(StudentConstructor,id,name)//构建闭包
queue.Push(c); //将闭包放到队列中
Lua code:
local c=queue:Pop() --从队列里取出下一个闭包
o=c.do_construct() --实际的创建过程
assert(o.id==31)
assert(o.name==“mark”)
如在说明书及权利要求当中使用了某些词汇来指称特定组件。本领域技术人员应可理解,硬件制造商可能会用不同名词来称呼同一个组件。本说明书及权利要求并不以名称的差异来作为区分组件的方式,而是以组件在功能上的差异来作为区分的准则。如在通篇说明书及权利要求当中所提及的“包含”为一开放式用语,故应解释成“包含但不限定于”。“大致”是指在可接收的误差范围内,本领域技术人员能够在一定误差范围内解决所述技术问题,基本达到所述技术效果。此外,“耦接”一词在此包含任何直接及间接的电性耦接手段。因此,若文中描述一第一装置耦接于一第二装置,则代表所述第一装置可直接电性耦接于所述第二装置,或通过其他装置或耦接手段间接地电性耦接
至所述第二装置。说明书后续描述为实施本申请的较佳实施方式,然所述描述乃以说明本申请的一般原则为目的,并非用以限定本申请的范围。本申请的保护范围当视所附权利要求所界定者为准。
还需要说明的是,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的商品或者系统不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种商品或者系统所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的商品或者系统中还存在另外的相同要素。
上述说明示出并描述了本申请的若干优选实施例,但如前所述,应当理解本申请并非局限于本文所披露的形式,不应看作是对其他实施例的排除,而可用于各种其他组合、修改和环境,并能够在本文所述申请构想范围内,通过上述教导或相关领域的技术或知识进行改动。而本领域人员所进行的改动和变化不脱离本申请的精神和范围,则都应在本申请所附权利要求的保护范围内。
Claims (10)
- 一种对象传递方法,其特征在于,包括:宿主线程中的宿主程序与脚本线程中的脚本程序交互时,所述宿主程序获取所述对象的构造函数以及原始数据;将所述对象的构造函数以及所述原始数据传递至所述脚本程序,由所述脚本程序在所述脚本线程上调用所述构造函数,根据所述原始数据创建所述对象。
- 如权利要求1所述的方法,其特征在于,所述将所述对象的构造函数以及原始数据传递至所述脚本程序包括:根据所述脚本程序的脚本语言类型,将所述构造函数转换为所述脚本语言类型的构造函数;将转换之后的构造函数以及所述原始数据传递至所述脚本程序。
- 如权利要求1所述的方法,其特征在于,所述将所述对象的构造函数以及原始数据传递至所述脚本程序包括:将所述对象的构造函数以及原始数据打包成闭包,传递至所述脚本程序。
- 如权利要求1所述的方法,其特征在于,将所述对象的构造函数以及原始数据传递至所述脚本程序之前,所述方法还包括:建立宿主程序与脚本程序之间的传递队列;所述将所述对象的构造函数以及原始数据传递至所述脚本程序包括:将所述对象的构造函数以及原始数据通过所述传递队列传递至所述脚本程序。
- 一种对象传递方法,其特征在于,包括:在宿主线程中的宿主程序与脚本线程中的脚本程序交互时,所述脚本程序获取所述宿主程序传递的构造函数以及原始数据;在脚本线程上调用所述构造函数,根据所述原始数据创建所述对象。
- 一种对象传递装置,其特征在于,包括:获取模块,用于在宿主线程中的宿主程序与脚本线程中的脚本程序交互时,获取所述对象的构造函数以及原始数据;其中,所述宿主线程与所述脚本线程不同;传递模块,用于将所述对象的构造函数以及原始数据传递至所述脚本程序,由所述脚本程序在所述脚本线程上调用所述构造函数,根据所述原始数据创建所述对象。
- 如权利要求6所述的装置,其特征在于,所述传递模块包括:转换单元,用于根据所述脚本程序的脚本语言类型,将所述构造函数转换为所述脚 本语言类型的构造函数;传递单元,用于将转换之后的构造函数以及所述原始数据传递至所述脚本程序。
- 如权利要求6所述的装置,其特征在于,所述传递模块具体用于将所述对象的构造函数以及原始数据打包成闭包,传递至所述脚本程序。
- 如权利要求6所述的装置,其特征在于,还包括:建立模块,用于建立宿主程序与脚本程序之间的传递队列;所述传递模块具体用于将所述对象的构造函数以及原始数据通过所述传递队列传递至所述脚本程序。
- 一种对象传递装置,其特征在于,包括:接收模块,用于在宿主线程中的宿主程序与脚本线程中的脚本程序交互时,所述脚本程序获取所述宿主程序传递的构造函数以及原始数据;创建模块,用于在脚本线程上调用所述构造函数,根据所述原始数据创建所述对象。
Applications Claiming Priority (2)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201510512106.4 | 2015-08-19 | ||
| CN201510512106.4A CN106469051B (zh) | 2015-08-19 | 2015-08-19 | 对象传递方法和装置 |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| WO2017028720A1 true WO2017028720A1 (zh) | 2017-02-23 |
Family
ID=58050705
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| PCT/CN2016/094321 Ceased WO2017028720A1 (zh) | 2015-08-19 | 2016-08-10 | 对象传递方法和装置 |
Country Status (2)
| Country | Link |
|---|---|
| CN (1) | CN106469051B (zh) |
| WO (1) | WO2017028720A1 (zh) |
Cited By (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN110825383A (zh) * | 2019-10-14 | 2020-02-21 | 北京奇艺世纪科技有限公司 | 一种视频交互方法、装置及计算机可读存储介质 |
| CN114624510A (zh) * | 2022-03-10 | 2022-06-14 | 厦门四信智慧电力科技有限公司 | 基于Lua脚本语言的数据处理方法、装置、设备及存储介质 |
Families Citing this family (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN107562516A (zh) * | 2017-08-07 | 2018-01-09 | 北京金山安全管理系统技术有限公司 | 多线程处理方法和装置、存储介质及处理器 |
| CN109032583B (zh) * | 2018-07-25 | 2022-06-17 | 北京小米移动软件有限公司 | 数据交互方法及装置 |
| CN110134386B (zh) * | 2019-04-04 | 2023-04-18 | 成都娄外科技有限公司 | 一种程序编辑方法和装置 |
Citations (6)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US6275868B1 (en) * | 1997-03-12 | 2001-08-14 | Microsoft Corporation | Script Engine interface for multiple languages |
| US20040205709A1 (en) * | 2001-05-09 | 2004-10-14 | Sun Microsystems, Inc. | Method,system, and program for providing patch expressions used in determining whether to install a patch |
| CN101458633A (zh) * | 2007-12-13 | 2009-06-17 | 华为软件技术有限公司 | 通过脚本程序访问宿主程序的方法及其系统和装置 |
| CN102222023A (zh) * | 2010-04-15 | 2011-10-19 | 微软公司 | 异步工作流 |
| CN104298534A (zh) * | 2014-10-23 | 2015-01-21 | 广州华多网络科技有限公司 | 基于Lua语言的编程方法和装置 |
| CN104391700A (zh) * | 2014-11-11 | 2015-03-04 | 百度在线网络技术(北京)有限公司 | 应用程序功能扩展方法和装置 |
Family Cites Families (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20080016253A1 (en) * | 2006-07-11 | 2008-01-17 | Boctor Design, Llc | Graphical user interface for navigating and manipulating objects exposed by a host |
| US8522200B2 (en) * | 2008-08-28 | 2013-08-27 | Microsoft Corporation | Detouring in scripting systems |
| CN102141917A (zh) * | 2011-04-02 | 2011-08-03 | 南京天溯自动化控制系统有限公司 | 基于IronPython脚本语言的多业务联动实现方法 |
| CN103825811A (zh) * | 2013-10-11 | 2014-05-28 | 江苏飞尚安全监测咨询有限公司 | 一种接入传感器协议自识别的物联网网关实现方案 |
-
2015
- 2015-08-19 CN CN201510512106.4A patent/CN106469051B/zh active Active
-
2016
- 2016-08-10 WO PCT/CN2016/094321 patent/WO2017028720A1/zh not_active Ceased
Patent Citations (6)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US6275868B1 (en) * | 1997-03-12 | 2001-08-14 | Microsoft Corporation | Script Engine interface for multiple languages |
| US20040205709A1 (en) * | 2001-05-09 | 2004-10-14 | Sun Microsystems, Inc. | Method,system, and program for providing patch expressions used in determining whether to install a patch |
| CN101458633A (zh) * | 2007-12-13 | 2009-06-17 | 华为软件技术有限公司 | 通过脚本程序访问宿主程序的方法及其系统和装置 |
| CN102222023A (zh) * | 2010-04-15 | 2011-10-19 | 微软公司 | 异步工作流 |
| CN104298534A (zh) * | 2014-10-23 | 2015-01-21 | 广州华多网络科技有限公司 | 基于Lua语言的编程方法和装置 |
| CN104391700A (zh) * | 2014-11-11 | 2015-03-04 | 百度在线网络技术(北京)有限公司 | 应用程序功能扩展方法和装置 |
Cited By (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN110825383A (zh) * | 2019-10-14 | 2020-02-21 | 北京奇艺世纪科技有限公司 | 一种视频交互方法、装置及计算机可读存储介质 |
| CN110825383B (zh) * | 2019-10-14 | 2023-08-22 | 北京奇艺世纪科技有限公司 | 一种视频交互方法、装置及计算机可读存储介质 |
| CN114624510A (zh) * | 2022-03-10 | 2022-06-14 | 厦门四信智慧电力科技有限公司 | 基于Lua脚本语言的数据处理方法、装置、设备及存储介质 |
Also Published As
| Publication number | Publication date |
|---|---|
| CN106469051B (zh) | 2020-03-27 |
| CN106469051A (zh) | 2017-03-01 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| US9740459B2 (en) | Automated generation of bridging code to augment a legacy application using an object-oriented language | |
| WO2017028720A1 (zh) | 对象传递方法和装置 | |
| CN111740948A (zh) | 数据包发布方法、动态更新方法、装置、设备及介质 | |
| US9811319B2 (en) | Software interface for a hardware device | |
| US10303449B2 (en) | Compiling non-native constants | |
| CN107659624A (zh) | 一种适用于云计算的异构云管理系统及方法 | |
| CN113590185B (zh) | 基于微前端的页面国际化配置方法、装置、设备及介质 | |
| US10817284B2 (en) | Melding of mediation flow service component architecture (SCA) components | |
| US12086627B2 (en) | Techniques for executing serverless functions on media items | |
| US9762700B2 (en) | Client-side aggregation of nested resource dependencies | |
| WO2019127904A1 (zh) | 应用程序运行方法、装置、计算机设备和存储介质 | |
| JP5811088B2 (ja) | データ処理システム及びデータ処理方法 | |
| US8291432B2 (en) | Providing invocation context to IMS service provider applications | |
| WO2022135592A1 (zh) | 模型训练程序镜像的生成方法、装置、设备及存储介质 | |
| CN107315360B (zh) | 测量仪器的远程控制方法和系统 | |
| CN115544304A (zh) | 文件解析方法、装置、可读存储介质及文件解析设备 | |
| CN108733432B (zh) | 编程环境下私有方法的实现方法、调用方法及其装置 | |
| CN119577740B (zh) | 一种Web应用插件的安全隔离与集成方法及装置 | |
| US10802855B2 (en) | Producing an internal representation of a type based on the type's source representation | |
| CN118331765B (zh) | 鸿蒙小程序运行时的jsBridge通信方法、装置及存储介质 | |
| CN112052051B (zh) | 插件处理方法、装置、设备及存储介质 | |
| US20190102230A1 (en) | Managing split packages in a module system | |
| CN117519691B (zh) | 应用程序处理方法、装置、计算机设备和存储介质 | |
| CN103207787B (zh) | 一种项目开发中数据包的加载方法及系统 | |
| CN118733199B (zh) | kvisor配置方法、装置及存储介质 |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| 121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 16836584 Country of ref document: EP Kind code of ref document: A1 |
|
| NENP | Non-entry into the national phase |
Ref country code: DE |
|
| 122 | Ep: pct application non-entry in european phase |
Ref document number: 16836584 Country of ref document: EP Kind code of ref document: A1 |