CN106610838B - Conversion method of multiple scripting languages - Google Patents

Conversion method of multiple scripting languages Download PDF

Info

Publication number
CN106610838B
CN106610838B CN201611222920.3A CN201611222920A CN106610838B CN 106610838 B CN106610838 B CN 106610838B CN 201611222920 A CN201611222920 A CN 201611222920A CN 106610838 B CN106610838 B CN 106610838B
Authority
CN
China
Prior art keywords
var
function
script
script engine
language
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.)
Active
Application number
CN201611222920.3A
Other languages
Chinese (zh)
Other versions
CN106610838A (en
Inventor
郭斌
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Kuwo Technology Co Ltd
Original Assignee
Beijing Kuwo Technology Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Beijing Kuwo Technology Co Ltd filed Critical Beijing Kuwo Technology Co Ltd
Priority to CN201611222920.3A priority Critical patent/CN106610838B/en
Publication of CN106610838A publication Critical patent/CN106610838A/en
Application granted granted Critical
Publication of CN106610838B publication Critical patent/CN106610838B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/51Source to source

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computing Systems (AREA)
  • Stored Programmes (AREA)
  • Devices For Executing Special Programs (AREA)

Abstract

The invention relates to a method for converting multiple scripting languages, which comprises the following steps: step 1, designing a composite data type VAR, wherein the composite data type VAR supports the free combination of six basic types; the six basic types are: integers, floating point numbers, strings, pointers, arrays, and dictionaries; the VAR is used for eliminating the difference between the scripting language and data in C + +; step 2, realizing a common interface for each script language to make an adapter; step 3, making or packaging a function code by using a C + + function, and then injecting the function code into the adapter in the step 2, wherein the C + + function meets the following conditions: the VAR array and the VAR dictionary are used as parameters, and the VAR is used as a return value. After the bottom layer function is written by the C + + language, the C + + function can be automatically applied to various script engines by the method, and a conversion layer does not need to be independently written for the script engine corresponding to each script language.

Description

Conversion method of multiple scripting languages
Technical Field
The invention relates to the technical field of computer programming, in particular to a conversion method of multiple scripting languages.
Background
Scripting languages (Script languages) are computer programming languages created to shorten the traditional write-compile-link-run (edge-compile-link-run) process. The script language has limited functions and slow execution speed, but is simple and convenient to use and is not easy to generate errors.
The C + + language has powerful functions and high execution speed, but is difficult to use and easy to make mistakes.
In the prior art, C + + language is usually used to provide necessary basic functions (also called as underlying functions) for the scripting language, and the scripting language is used to write logic, which is a common scheme for combining the scripting language and the C + + language to fully exert their respective advantages to compensate their respective disadvantages. The disadvantages of this solution are:
when necessary basic functions are provided for a scripting language by using a C + + language, codes of C + + extension scripting language functions are needed, and the codes of the C + + extension scripting language functions are not universal, so that underlying functions written for one scripting language are difficult to apply to another scripting language.
Prior art solutions to this are typically: the method comprises the steps of firstly writing bottom layer functions by using C + + language, then independently writing a conversion layer for a script engine (the script engine is an interpreter of computer programming language, such as asp and php for building a website, and the like, wherein the function of the script engine is to interpret and execute program text of a user, translate the program text of the script language into machine codes which can be executed by a computer, and complete a series of functions) corresponding to each script language, and the conversion layer corresponds to the script engine one by one.
Disclosure of Invention
Aiming at the defects in the prior art, the invention aims to provide a conversion method for multiple scripting languages, after the bottom layer functions are written by using the C + + language, the C + + functions can be automatically applied to various different scripting engines by the method, and a conversion layer does not need to be independently written for the scripting engine corresponding to each scripting language.
In order to achieve the above purposes, the technical scheme adopted by the invention is as follows:
a method for converting multiple scripting languages is characterized by comprising the following steps:
step 1, designing a composite data type VAR, wherein the composite data type VAR supports the free combination of six basic types;
the six basic types are: integers, floating point numbers, strings, pointers, arrays, and dictionaries;
the VAR is used for eliminating the difference between the scripting language and data in C + +;
step 2, realizing a common interface for each script language to make an adapter;
step 3, making or packaging a function code by using a C + + function, and then injecting the function code into the adapter in the step 2, wherein the C + + function meets the following conditions: the VAR array and the VAR dictionary are used as parameters, and the VAR is used as a return value.
On the basis of the above technical solution, in step 1, the element of each item in the array is also VAR, and the key of each item in the dictionary is a character string type, and the value of the character string type is VAR.
On the basis of the above technical solution, in step 1, the VAR implements support for six basic types of data by using C + + classes.
On the basis of the above technical solution, in step 1, the script language includes but is not limited to: JS, Lua, php.
On the basis of the technical scheme, the specific steps of the step 2 are decomposed as follows:
step 2.1, a conversion function of the script language data type and the VAR is realized, and the script language data type is respectively expressed by an integer, a floating point number, a character string, a pointer, an array and a dictionary of the VAR;
step 2.2, registering a C + + class or a function in a script engine, wherein the function refers to a function directly called in a script language, and the class refers to a script engine class or an object prototype which can be accessed in the script language;
step 2.3, a function conforming to the script engine format is realized as a converter from the script language function or the function in the class to the C + + realization in the step 2.2;
step 2.4, calling a script engine to execute the script file;
and 2.5, realizing the function of executing the script function, and executing the calling function of the script engine by using the VAR to save the function name or the ID as a parameter.
On the basis of the technical scheme, the specific steps of the step 3 are as follows:
step 3.1, as described in step 2.3 above, implementing or encapsulating the function code using the VAR array and the VAR dictionary as parameters and the C + + function with the VAR as a unique return value;
and 3.2, registering the C + + function realized in the step 3.1 into a common interface of the script engine through the step 2.2, wherein the VAR shields the difference of data, functions and objects in different script engines, so that the method can be applied to all script engine adapters without any modification.
On the basis of the technical scheme, when an unknown script engine is encountered, the adapter is realized according to the method of the step 2 according to each script engine.
On the basis of the technical scheme, when the data types in the unknown script engine are richer than the VAR, the data types transmitted to the adapter can only be the combination supported by the VAR;
when the data types in the unknown script engine are not as rich as the VAR, modifying in the adapter, simplifying the integer, floating point number and pointer of the VAR into character strings, and converting the array of the VAR into a dictionary;
for unknown script engines which are not supported by hyphenation strings and dictionaries, simulating data types supported by the unknown script engines according to specific conditions;
unknown script engines of character strings and dictionaries cannot be simulated, and corresponding error prompts are not supported and returned.
After the bottom layer function is written by the C + + language, the C + + function can be automatically applied to various script engines by the method, and a conversion layer does not need to be independently written for the script engine corresponding to each script language.
The conversion method of multiple scripting languages is easy to use and good in stability and reliability.
The conversion method of multiple scripting languages has good applicability to unknown scripting engines.
Drawings
The invention has the following drawings:
FIG. 1 is a schematic diagram of the workflow of a script engine manager adapter (engine manager for short).
Detailed Description
The present invention will be described in further detail with reference to the accompanying drawings.
First, the script engine is briefly analyzed:
the script engine and C + + call each other, which can be understood simply as: mutual calling between the C + + function and the script engine function, and conversion of the C + + data type and the script language data type.
Wherein:
first, the implementation of a C + + call script engine function requires obtaining an object ID and a member function ID from the script engine, where the object ID and the member function ID are both abstract IDs as long as they can be used to identify the object or the function. For example: the object ID can be expressed by a string of function names with object pointers in jsid, lua engine in the Spidermonkey engine.
Obviously, the object ID and the member function ID do not have general applicability to different scripting languages, but the application code does not need to identify them, and the framework code identifies them and calls them.
Second, when the script engine calls C + +, the C + + is needed to provide an object pointer and a member function pointer.
Third, although the C + + data type and the scripting language data type are not general, the concept of data is general, and data can be general by implementing the concept of data and then converting the C + + data type and the scripting language data type into the concept of data.
The invention relates to a method for converting multiple scripting languages, which comprises the following steps:
step 1, designing a composite data type VAR, wherein the composite data type VAR supports the free combination of six basic types (basic structures);
the six basic types are: integers, floating point numbers, strings, pointers, arrays, and dictionaries; wherein the element of each term in the array is also VAR, and the key of each term in the dictionary is a string type, the value of the string type being VAR;
the VAR is used for eliminating the difference between the scripting language and data in C + +;
step 2, realizing a common interface for each script language to make an adapter;
step 3, making or packaging a function code by using a C + + function, and then injecting the function code into the adapter in the step 2, wherein the C + + function meets the following conditions: the VAR array and the VAR dictionary are used as parameters, and the VAR is used as a return value.
On the basis of the technical scheme, the VAR adopts C + + class to realize the support of six basic types of data. For example: the method can be realized by the following codes:
Figure BDA0001193023840000051
Figure BDA0001193023840000061
on the basis of the technical solution, the script language includes but is not limited to: JS, Lua, php. JS is called javascript; lua is a small scripting language designed to be embedded in an application to provide flexible extension and customization of the application; PHP refers to Hypertext Preprocessor, chinese name: the hypertext preprocessor is a universal open source script language, grammar absorbs the characteristics of C language, Java and Perl, is beneficial to learning, is widely used, and is mainly suitable for the field of Web development.
On the basis of the technical scheme, the specific steps of the step 2 are decomposed as follows:
step 2.1, a conversion function of the script language data type and the VAR is realized, and the script language data type is respectively expressed by an integer, a floating point number, a character string, a pointer, an array and a dictionary of the VAR;
step 2.2, registering a C + + class or a function in a script engine, wherein the function refers to a function directly called in a script language, and the class refers to a script engine class or an object prototype which can be accessed in the script language;
step 2.3, a function conforming to the script engine format is realized as a converter from the script language function or the function in the class to the C + + realization in the step 2.2;
step 2.4, calling a script engine to execute the script file;
and 2.5, realizing the function of executing the script function, and executing the calling function of the script engine by using the VAR to save the function name or the ID as a parameter. Wherein:
the ID can be expressed in different ways for different script engines, such as by integer representation of jsid of the Spidermonkey engine, or by string representation of the name of the closure function in the lua engine.
For example, take a spidermonden key engine (hereinafter referred to as js engine for short) as an example:
2.1, expressing jsid of a function in js by using a pointer of the js; representing the character string, the integer, the floating point number, the object attribute, the array and the object in the js by the character string, the integer, the floating point number, the dictionary, the array and the pointer of the VAR respectively;
step 2.2, defining a member function of the class by combining JS _ DefineObject of the JS engine with JS _ DefineFunction or directly using JS _ DefineFunction to register a function which can be directly called in JS with a global object described in the JS engine as the class;
step 2.3, the converter converts the parameters and the return values through the conversion function realized in the step 2.1; then transferring the conversion result to a C + + function which takes the VAR array and the VAR dictionary as parameters and the VAR as a unique return value; all parameters transferred to C + + in terms of VAR array items representing js, and environment information transferred in a VAR dictionary, such as pointers of class objects, pointers of engine objects and the like;
step 2.4, compiling the JS script File into a JSScript object by calling a JS _ CompleUTF 8File function of the JS engine, and then executing the JSScript object by using a JS _ ExecuteScript function;
and 2.5, executing a JS function of a given character string name by calling the JS _ CallFunctionName function of the JS engine or executing a function of a given function ID by using the JS _ CallFunctionName function.
On the basis of the technical scheme, the specific steps of the step 3 are as follows:
step 3.1, as described in step 2.3 above, implementing or encapsulating the function code using the VAR array and the VAR dictionary as parameters and the C + + function with the VAR as a unique return value;
and 3.2, registering the C + + function realized in the step 3.1 into a common interface of the script engine through the step 2.2, wherein the VAR shields the difference of data, functions and objects in different script engines, so that the method can be applied to all script engine adapters without any modification.
On the basis of the technical scheme, when an unknown script engine is encountered, the adapter is realized according to the method of the step 2 according to each script engine.
Wherein: when the data type in the unknown script engine is richer than the VAR, the combination of the VAR support is only possible to transfer to the adapter because the parameter of our function is limited by the VAR; when the data type in the unknown script engine is not as rich as the VAR, the data type can be modified in the adapter, the integer, the floating point number and the pointer of the VAR can be reduced into character strings, and the array of the VAR is converted into a dictionary.
And for unknown script engines which are not supported by the hyphenation and the dictionary, simulating the data types supported by the unknown script engines according to specific conditions.
Unknown script engines that cannot simulate strings and dictionaries do not consider because their programming ideas are too unique, such as: and the corresponding error prompt is not supported and returned.
The following are specific examples.
Case (2): and various script engines are supported as HTTP service programs of the WEB page.
An HTTP servlet is implemented in C + +. And after receiving the request, generating a character string such as js representing the representative type of the script engine type and a local file path according to a matching result of the configured regular expression and the url of the HTTP request. Then, the calling engine manager generates a specific script engine adapter by taking the type character string as a parameter, and injects a series of functions used in the script into the script engine adapter. And loading the matched local file by using the adapter, calling an entry function of the script by the C + + through the script engine adapter after the loading is successful, and generating and outputting the content of the dynamic page in the script code through the injected object and function.
As shown in FIG. 1, the script engine manager acts as a creator of the various script engine adapters. It creates a specific script engine adapter from the string name (e.g., encountering the object of php creating php script engine adapter), each engine adapter is integrated from a unified script engine interface. After the adapter with the script engine adapter interface is created by the engine manager, the specific behavior of the adapter is not required to be related to the user. Therefore, the user does not need to master the technical details of the real script engine behind and can operate different script engines only by operating according to the unified interface of the script engine.
Those not described in detail in this specification are within the skill of the art.

Claims (7)

1. A method for converting multiple scripting languages is characterized by comprising the following steps:
step 1, designing a composite data type VAR, wherein the composite data type VAR supports the free combination of six basic types;
the six basic types are: integers, floating point numbers, strings, pointers, arrays, and dictionaries;
the VAR is used for eliminating the difference between the scripting language and the data in C + +;
step 2, implementing an adapter for each scripting language;
the specific steps of step 2 are decomposed as follows:
step 2.1, a conversion function of the script language data type and the VAR is realized, and the script language data type is respectively expressed by an integer, a floating point number, a character string, a pointer, an array and a dictionary of the VAR;
step 2.2, registering a C + + class or a function in a script engine, wherein the function refers to a function directly called in a script language, and the class refers to a script engine class or an object prototype which can be accessed in the script language;
step 2.3, a function conforming to the script engine format is realized and is used as a converter from the function or the function in the class in the step 2.2 to the C + + realization;
step 2.4, calling a script engine to execute the script file;
step 2.5, realizing the function of executing the function, and executing the function calling function of the script engine by using the VAR to save the function name or ID as a parameter;
step 3, making or packaging a function code by using a C + + function, and then injecting the function code into the adapter in the step 2, wherein the C + + function meets the following conditions: the VAR array and the VAR dictionary are used as parameters, and the VAR is used as a return value.
2. The method for converting a plurality of scripting languages of claim 1, wherein: in step 1, the element of each item in the array is also VAR, and the key of each item in the dictionary is a character string type, and the value of the character string type is VAR.
3. The method for converting a plurality of scripting languages of claim 1, wherein: in step 1, the VAR implements support for six basic types of data by using C + + classes.
4. The method for converting a plurality of scripting languages of claim 1, wherein: in step 1, the scripting language includes but is not limited to: JS, Lua, php.
5. The method for converting a plurality of scripting languages of claim 1, wherein: the specific steps of step 3 are as follows:
step 3.1, using the VAR array and the VAR dictionary as parameters and using the VAR as a C + + function realization or encapsulation function code of the unique return value;
and 3.2, registering the C + + function realized in the step 3.1 into an adapter of the script engine according to the step 2.2.
6. The method for converting a plurality of scripting languages of claim 1, wherein: when an unknown script engine is encountered, its adapter is implemented according to the method of step 2 according to each script engine.
7. The method for converting a plurality of scripting languages of claim 6, wherein: when the unknown script engine has more data types than the VAR, only the data types supported by the VAR are transmitted to the adapter;
when the unknown script engine is less than the data type of the VAR, modifying in the adapter, simplifying the integer, floating point number and pointer of the VAR into character strings, and converting the array of the VAR into a dictionary;
simulating an unknown script engine which does not support character strings and dictionaries by using data types supported by the unknown script engine;
if the unknown script engine cannot simulate the character string and the dictionary, the unknown script engine is not supported and an error prompt is returned.
CN201611222920.3A 2016-12-27 2016-12-27 Conversion method of multiple scripting languages Active CN106610838B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201611222920.3A CN106610838B (en) 2016-12-27 2016-12-27 Conversion method of multiple scripting languages

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201611222920.3A CN106610838B (en) 2016-12-27 2016-12-27 Conversion method of multiple scripting languages

Publications (2)

Publication Number Publication Date
CN106610838A CN106610838A (en) 2017-05-03
CN106610838B true CN106610838B (en) 2020-04-24

Family

ID=58636730

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201611222920.3A Active CN106610838B (en) 2016-12-27 2016-12-27 Conversion method of multiple scripting languages

Country Status (1)

Country Link
CN (1) CN106610838B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112099838B (en) * 2019-06-17 2023-08-15 腾讯科技(深圳)有限公司 Method, device and storage medium for determining version difference

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1949186A (en) * 2006-11-17 2007-04-18 深圳市领测科技有限公司 Program testing system and mapping method for said program testing system
CN101158894A (en) * 2006-10-08 2008-04-09 上海科泰世纪科技有限公司 Dynamically automatic adapting programming system and method in modular soft software system
CN104182234A (en) * 2014-08-25 2014-12-03 杭州华为数字技术有限公司 Business processing method and business system
CN105068854A (en) * 2015-08-07 2015-11-18 杭州古北电子科技有限公司 Method for controlling different products by using same rule

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101158894A (en) * 2006-10-08 2008-04-09 上海科泰世纪科技有限公司 Dynamically automatic adapting programming system and method in modular soft software system
CN1949186A (en) * 2006-11-17 2007-04-18 深圳市领测科技有限公司 Program testing system and mapping method for said program testing system
CN104182234A (en) * 2014-08-25 2014-12-03 杭州华为数字技术有限公司 Business processing method and business system
CN105068854A (en) * 2015-08-07 2015-11-18 杭州古北电子科技有限公司 Method for controlling different products by using same rule

Also Published As

Publication number Publication date
CN106610838A (en) 2017-05-03

Similar Documents

Publication Publication Date Title
Marrs JSON at work: practical data integration for the web
CN106970802B (en) Method and device for integrating programming script language in domain-specific language
US9886268B1 (en) Dual programming interface
AU2015218520B2 (en) Service extraction and application composition
CN103064721A (en) Sharing of first class objects across multiple interpreted programming languages
EP3008585A1 (en) Automatic source code generation
US7409619B2 (en) System and methods for authoring domain specific rule-driven data generators
CN114780100B (en) Compiling method, electronic device and storage medium
CN109032936A (en) A kind of desktop automatic test development approach and system
CN112860584B (en) Workflow model-based testing method and device
CN106610838B (en) Conversion method of multiple scripting languages
Voron Building Data Science Applications with FastAPI: Develop, manage, and deploy efficient machine learning applications with Python
Zhao et al. Pattern-based design evolution using graph transformation
CN113138755A (en) JSON serialization and deserialization optimization method and system
Shute Advanced JavaScript: Speed up web development with the powerful features and benefits of JavaScript
US7627852B1 (en) Embedding an interpreter within an application written in a different programming language
CN105279032A (en) Method and apparatus for synchronizing interface message and javaBean
Binsztok et al. Opa: Up and Running: Rapid and Secure Web Development
Arcaini et al. Unified syntax for abstract state machines
bin Uzayr Golang: The ultimate guide
Pomante et al. A model-driven approach for the development of an ide for spacecraft on-board software
US20230334069A1 (en) Cross-platform content management
CN113741900B (en) Development method and device of front-end page application and related equipment
Jeffery Build Your Own Programming Language: A programmer's guide to designing compilers, interpreters, and DSLs for solving modern computing problems
Stutterheim Improving the UHC JavaScript backend

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant