CN106610838A - Method for converting multiple script languages - Google Patents
Method for converting multiple script languages Download PDFInfo
- Publication number
- CN106610838A CN106610838A CN201611222920.3A CN201611222920A CN106610838A CN 106610838 A CN106610838 A CN 106610838A CN 201611222920 A CN201611222920 A CN 201611222920A CN 106610838 A CN106610838 A CN 106610838A
- Authority
- CN
- China
- Prior art keywords
- var
- script
- function
- engine
- script engine
- 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.)
- Granted
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/30—Creation or generation of source code
- G06F8/31—Programming languages or programming paradigms
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/51—Source to source
Landscapes
- Engineering & Computer Science (AREA)
- General Engineering & Computer Science (AREA)
- Software Systems (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 script languages. The method comprises the following steps: step 1, designing a composite data type VAR, wherein the composite data type VAR supports free combinations of six fundamental types, the six fundamental types are an integer, a floating-point number, a character string, a pointer, an array and a dictionary, and the VAR is used for eliminating differentiations of data in the script languages and C++; step 2, realizing a public interface for each of the script languages to take as an adapter; and step 3, producing or encapsulating function codes by a C++ function, and then injecting the function codes to the adapter in the step 2, wherein the C++ function meets the following conditions: the VAR array and the VAR dictionary are taken as parameters and the VAR is taken as a returned value. According to the method related by the invention, after bottom functions are written by a C++ language, the C++ function can be automatically applied to various different script engines via the method, and a conversion layer does not need to be written for the script engines corresponding to each of the script languages separately.
Description
Technical field
The present invention relates to computer programming field, the specifically conversion method of one kind of multiple scripts.
Background technology
Script (Script languages) be in order to shorten it is traditional write-compile-link-run (edit-
Compile-link-run) process and the computer programming language that creates.The function limited enforcement speed of script is slow, but makes
It is not easy mistake occur with simplicity.
The powerful speed that performs of C Plus Plus is fast but larger using difficulty, easily error.
In the prior art, it will usually provide necessary basic function (also known as bottom work(for script with C Plus Plus
Can), logic is write with script, this is to be combined script with C Plus Plus to give full play to respective advantage and make up respective shortcoming
Common scheme.The shortcoming of this scheme is:
When necessary basic function is provided for script with C Plus Plus, need to use C++ extension script functions
Code, due to C++ extend script function code do not possess versatility, this causes the bottom write for a kind of script
Function is difficult to apply in another script.
Prior art is typically to this solution:First bottom function is finished writing with C Plus Plus, be then individually for again every kind of
(script engine, is exactly the interpreter of a computer programming language to the corresponding script engine of script, as networking station
Asp, php etc., its function is to explain the program documentaion for performing user, the program documentaion of script is translated into into computer capacity and is held
Capable machine code, completes a series of function) conversion layer is write, conversion layer and script engine are corresponded.
The content of the invention
For defect present in prior art, it is an object of the invention to provide the conversion side of one kind of multiple scripts
Method, after bottom function is finished writing with C Plus Plus, can be automatically applied to a variety of scripts and draw by this method by C++ functions
In holding up, without the need for being individually for the corresponding script engine of every kind of script again a conversion layer is write.
To reach object above, the present invention is adopted the technical scheme that:
The conversion method of one kind of multiple scripts, it is characterised in that comprise the steps:
Step 1, designs composite data type VAR, and composite data type VAR supports the freedom of six kinds of fundamental types
Combination;
Six kinds of fundamental types are:Integer, floating number, character string, pointer, array and dictionary;
The VAR is used to eliminate the differentiation of script and data in C++;
Step 2, is that every kind of script realizes that common interface makes adapter;
Step 3, makes or encapsulation function code of C++ functions, is then poured in the adapter described in step 2,
The C++ functions meet following condition:Using VAR arrays and VAR dictionaries as parameter, using VAR as return value.
On the basis of above-mentioned technical proposal, in step 1, the element of each is also VAR in array, and each in dictionary
The key of item is character string type, and the value of character string type is VAR.
On the basis of above-mentioned technical proposal, in step 1, the VAR realizes the number to six kinds of fundamental types using C++ class
According to support.
On the basis of above-mentioned technical proposal, in step 1, the script is included but is not limited to:JS、Lua、php.
On the basis of above-mentioned technical proposal, the concrete steps of step 2 decompose as follows:
Step 2.1, realizes the transfer function of a script data type and VAR, by script data type point
Do not represented with the integer of VAR, floating number, character string, pointer, array and dictionary;
Step 2.2, C++ class or function are registered in script engine, and the function refers to what is directly invoked in script
Function, the class refers to the script engine class being able to access that in script or object prototypes;
Step 2.3, realizes a function for meeting script engine form, as script function described in step 2.2 or
The transducer that the function of apoplexy due to endogenous wind is realized to its C++;
Step 2.4, calls script engine perform script file;
Step 2.5, realizes the function of perform script function, by preserving function name or ID as a parameter to holding with VAR
The call function function of row script engine.
On the basis of above-mentioned technical proposal, step 3 is comprised the following steps that:
Step 3.1, as described in above-mentioned step 2.3, using VAR arrays and VAR dictionaries as parameter and using VAR as only
The C++ functions of one return value are realized or encapsulation function code;
Step 3.2, by described in above-mentioned steps 2.2, the C++ power functions that 3.1 steps are realized being registered to into script engine
Common interface in, because VAR has masked the difference of data, function and object in different script engines, so it can be fitted
For all of script engine adapter without any modification.
On the basis of above-mentioned technical proposal, when unknown script engine is run into, according to every kind of script engine according to step 2
Method go to realize its adapter.
On the basis of above-mentioned technical proposal, when data type is more enriched than VAR in unknown script engine, pass to
The combination for being only possible to be VAR supports of adapter;
When the data type in unknown script engine is abundant not as VAR, make an amendment in adapter, by the integer of VAR,
Floating number, pointer are simplified as character string, and the array of VAR is converted into into dictionary;
For the unknown script engine that hyphen string and dictionary are not supported, as the case may be with the data class that it is supported
Type is simulated;
The unknown script engine of character string and dictionary cannot be simulated, corresponding miscue is not supported and return.
The conversion method of various scripts of the present invention, after bottom function is finished writing with C Plus Plus, by we
Method can be automatically applied to C++ functions in a variety of script engines, without the need for being individually for the corresponding foot of every kind of script again
This engine writes a conversion layer.
The conversion method of various scripts of the present invention, it is easy to use, stability, good reliability.
The conversion method of various scripts of the present invention, equally has extraordinary being suitable for unknown script engine
Property.
Description of the drawings
The present invention has drawings described below:
Fig. 1 script engine manager adapter (abbreviation engine manager) workflow schematic diagrams.
Specific embodiment
The present invention is described in further detail below in conjunction with accompanying drawing.
First, simple analysis once script engine:
Script engine is called mutually with C++, can be simplified and is interpreted as:It is mutual between C++ functions and script engine function
Call, the conversion of C++ data types and script data type.
Wherein:
First, C++ call the realization of script engine function to need to obtain object ID and member function ID from script engine,
The object ID and member function ID are an abstract ID, as long as the data of the object or the function can be used for recognizing all
Can be with.For example:Object ID function name can be represented in jsid in Spidermonkey engines, lua engine with pointer to object
The string table of word reaches member function ID.
Obviously, although the object ID and member function ID do not have general applicability to different scripts, should
With code and them need not be recognized, skeleton code recognizes them and call just can be with.
Second, when script engine calls C++, need C++ to provide pointer to object and pointer to member function.
3rd, although C++ data types and script data type be not general, data this concepts be have it is universal
Property, it is then that C++ data types and script data type is general to this data as long as we realize data this concepts
Thought is changed just can accomplish general data.
The conversion method of various scripts of the present invention, comprises the steps:
Step 1, designs composite data type VAR, and composite data type VAR supports that six kinds of fundamental types are (basic
Structure) independent assortment;
Six kinds of fundamental types are:Integer, floating number, character string, pointer, array and dictionary;It is wherein each in array
The element of item is also VAR, and the key of each is character string type in dictionary, and the value of character string type is VAR;
The VAR is used to eliminate the differentiation of script and data in C++;
Step 2, is that every kind of script realizes that common interface makes adapter;
Step 3, makes or encapsulation function code of C++ functions, is then poured in the adapter described in step 2,
The C++ functions meet following condition:Using VAR arrays and VAR dictionaries as parameter, using VAR as return value.
On the basis of above-mentioned technical proposal, the VAR realizes propping up for the data to six kinds of fundamental types using C++ class
Hold.For example:Can be realized by code below:
On the basis of above-mentioned technical proposal, the script is included but is not limited to:JS、Lua、php.JS full name are
javascript;Lua is a compact script, its purpose of design be in order to be embedded in application program in, so as to for application
Program provides flexible extension and customizes function;PHP refers to Hypertext Preprocessor, Chinese name:" hypertext is located in advance
Reason device ", is a kind of general script of increasing income, the characteristics of grammer absorbs C language, Java and Perl, beneficial to study, using wide
It is general, it is primarily adapted for use in Web development fields.
On the basis of above-mentioned technical proposal, the concrete steps of step 2 decompose as follows:
Step 2.1, realizes the transfer function of a script data type and VAR, by script data type point
Do not represented with the integer of VAR, floating number, character string, pointer, array and dictionary;
Step 2.2, C++ class or function are registered in script engine, and the function refers to what is directly invoked in script
Function, the class refers to the script engine class being able to access that in script or object prototypes;
Step 2.3, realizes a function for meeting script engine form, as script function described in step 2.2 or
The transducer that the function of apoplexy due to endogenous wind is realized to its C++;
Step 2.4, calls script engine perform script file;
Step 2.5, realizes the function of perform script function, by preserving function name or ID as a parameter to holding with VAR
The call function function of row script engine.Wherein:
The ID is having different method for expressing, such as the jsid integer tables of Spidermonkey engines to different script engines
Show, or with the title string representation of Closure Function in lua engines.
For example, by taking SpiderMonkey engines (hereinafter referred to as js engines) as an example:
Step 2.1, with the pointer gauge of js the jsid of function in js is reached;By the character string in js, integer, floating number,
Object attributes, array, object are respectively with character string, integer, floating number, dictionary, array, the pointer representation of VAR;
Step 2.2, defines class and combines JS_DefineFunction definition classes by the JS_DefineObject of js engines
Member function or directly using JS_DefineFunction with the global object described in js engines as class registration can be in js
In the function that directly invokes;
Step 2.3, the transducer does the conversion of parameter and return value by the transfer function that step 2.1 is realized;Then will
Transformation result is passed to using VAR arrays and VAR dictionaries as parameter and using VAR as the C++ functions of unique return value;With
VAR array items represent that js passes to all parameters of C++, with VAR dictionary delivery context information, the such as pointer of class object, engine
Pointer of object etc.;
Step 2.4, is compiled as js script files by calling the JS_CompileUTF8File functions of js engines
JSScript objects, then perform the JSScript objects by JS_ExecuteScript functions;
Step 2.5, by calling the JS_CallFunctionName functions of js engines a given string name is performed
Js functions or by JS_CallFunction functions perform a given function ID function.
On the basis of above-mentioned technical proposal, step 3 is comprised the following steps that:
Step 3.1, as described in above-mentioned step 2.3, using VAR arrays and VAR dictionaries as parameter and using VAR as only
The C++ functions of one return value are realized or encapsulation function code;
Step 3.2, by described in above-mentioned steps 2.2, the C++ power functions that 3.1 steps are realized being registered to into script engine
Common interface in, because VAR has masked the difference of data, function and object in different script engines, so it can be fitted
For all of script engine adapter without any modification.
On the basis of above-mentioned technical proposal, when unknown script engine is run into, according to every kind of script engine according to step 2
Method go to realize its adapter.
Wherein:When data type is more enriched than VAR in unknown script engine, because our function parameter is by VAR
Limit, thus pass to adapter be only possible to be VAR support combination;When the data type in unknown script engine is not so good as
When VAR enriches, can make an amendment in adapter, the integer of VAR, floating number, pointer can be simplified as character string, by VAR
Array be converted into dictionary.
For the unknown script engine that hyphen string and dictionary are not supported, as the case may be with the data class that it is supported
Type is simulated.
The unknown script engine of character string and dictionary cannot be simulated, because its programming idea is excessively unique, therefore is not considered, example
Such as:Do not support and return corresponding miscue.
It is below specific embodiment.
Case:Support various script engines as the HTTP service program of WEB page.
A HTTP service program is realized with C++.According to the regular expression and HTTP request of configuration after request is received
The matching result of url generate such as js and one local file road of character string of a representative type for representing script engine type
Footpath.Then engine manager is called to generate a specific script engine adapter by parameter of type character string, and to the foot
A series of function that this engine adapter is injected used in scripts.The local file that this adapter loading is matched is reused,
After loading success, C++ calls the entrance function of script by script engine adapter, by the object of injection in scripted code
And the content of dynamic page is generated and exported by function.
As shown in figure 1, script engine manager plays a founder to various different script engine adapters.It
Specific script engine adapter (such as running into the object that php creates php script engine adapters) is created according to string name,
Each engine adapter is from unified script engine Interface integration.The adapter of script engine adaptor interface is completed by engine
Manager is created that after coming that its specific behavior does not need relation for user.Thus user grasps the back of the body without oneself
Ins and outs of true script engine afterwards, as long as go to operate according to script engine unified interface just can operate different scripts to draw
Hold up.
The content not being described in detail in this specification belongs to prior art known to professional and technical personnel in the field.
Claims (8)
1. the conversion method of one kind of multiple scripts, it is characterised in that comprise the steps:
Step 1, designs composite data type VAR, and composite data type VAR supports free group of six kinds of fundamental types
Close;
Six kinds of fundamental types are:Integer, floating number, character string, pointer, array and dictionary;
The VAR is used to eliminate the differentiation of script and data in C++;
Step 2, is that every kind of script realizes that common interface makes adapter;
Step 3, makes or encapsulation function code of C++ functions, is then poured in the adapter described in step 2, the C
++ function meets following condition:Using VAR arrays and VAR dictionaries as parameter, using VAR as return value.
2. the conversion method of various scripts as claimed in claim 1, it is characterised in that:In step 1, each item in array
Element be also VAR, and the key of each is character string type in dictionary, and the value of character string type is VAR.
3. the conversion method of various scripts as claimed in claim 1, it is characterised in that:In step 1, the VAR adopts C
++ class realizes the support of the data to six kinds of fundamental types.
4. the conversion method of various scripts as claimed in claim 1, it is characterised in that:In step 1, the script
Including but not limited to:JS、Lua、php.
5. the conversion method of various scripts as claimed in claim 1, it is characterised in that:The concrete steps of step 2 are decomposed
It is as follows:
Step 2.1, realizes the transfer function of a script data type and VAR, and script data type is used respectively
The integer of VAR, floating number, character string, pointer, array and dictionary are represented;
Step 2.2, C++ class or function are registered in script engine, and the function refers to the function directly invoked in script,
The class refers to the script engine class being able to access that in script or object prototypes;
Step 2.3, realizes a function for meeting script engine form, used as script function or apoplexy due to endogenous wind described in step 2.2
The transducer realized to its C++ of function;
Step 2.4, calls script engine perform script file;
Step 2.5, realizes the function of perform script function, by preserving function name or ID with VAR as a parameter to performing foot
The call function function of this engine.
6. the conversion method of various scripts as claimed in claim 5, it is characterised in that:Step 3 is comprised the following steps that:
Step 3.1, as described in above-mentioned step 2.3, using VAR arrays and VAR dictionaries as parameter and using VAR as uniquely returning
The C++ functions for returning value are realized or encapsulation function code;
Step 3.2, by described in above-mentioned steps 2.2, the C++ power functions that 3.1 steps are realized being registered to into the public affairs of script engine
Altogether in interface, because VAR has masked the difference of data, function and object in different script engines, so it goes for
All of script engine adapter is without any modification.
7. the conversion method of various scripts as claimed in claim 1, it is characterised in that:When running into unknown script engine
When, gone to realize its adapter according to the method for step 2 according to every kind of script engine.
8. the conversion method of various scripts as claimed in claim 7, it is characterised in that:When data in unknown script engine
Type than VAR more enrich when, pass to adapter be only possible to be VAR support combination;
When the data type in unknown script engine is abundant not as VAR, make an amendment in adapter, by the integer of VAR, floating-point
Number, pointer are simplified as character string, and the array of VAR is converted into into dictionary;
For the unknown script engine that hyphen string and dictionary are not supported, the data type supported with it as the case may be is done
Simulation;
The unknown script engine of character string and dictionary cannot be simulated, corresponding miscue is not supported and return.
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 true CN106610838A (en) | 2017-05-03 |
CN106610838B 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) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN112099838A (en) * | 2019-06-17 | 2020-12-18 | 腾讯科技(深圳)有限公司 | Method, device and storage medium for determining version difference |
Citations (4)
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 |
-
2016
- 2016-12-27 CN CN201611222920.3A patent/CN106610838B/en active Active
Patent Citations (4)
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 |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN112099838A (en) * | 2019-06-17 | 2020-12-18 | 腾讯科技(深圳)有限公司 | Method, device and storage medium for determining version difference |
CN112099838B (en) * | 2019-06-17 | 2023-08-15 | 腾讯科技(深圳)有限公司 | Method, device and storage medium for determining version difference |
Also Published As
Publication number | Publication date |
---|---|
CN106610838B (en) | 2020-04-24 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN102033748B (en) | Method for generating data processing flow codes | |
CN106202207B (en) | HBase-ORM-based indexing and retrieval system | |
AU2015218520B2 (en) | Service extraction and application composition | |
CN106648587A (en) | Annotation-based Web application code generation method | |
CN107451068A (en) | Use-case operation method, device, computing device and storage medium | |
CN111078555B (en) | Test file generation method, system, server and storage medium | |
CN103942086B (en) | The method of the establishment based on AADL, analysis and emulation hybrid system model | |
CN103810275A (en) | Method and device for data interaction between non-relation type database and relation type database | |
CN106095398B (en) | Big data development and application method and device based on DSL | |
CN104834507A (en) | Frame driving method of application construction platform | |
CN108509199A (en) | Method, device, equipment and storage medium for automatically generating Chinese annotations | |
US20200050714A1 (en) | Systemc model generation method and computer-readable recording medium recording systemc model generation program | |
WO2018233673A1 (en) | Method and apparatus for configuring model code in controller, and storage medium | |
CN108170435A (en) | A kind of source code conversion method, device and equipment | |
CN115469941A (en) | Automatic configuration processing method and system for wind control index calculation development based on FlinkSQL | |
CN104750468B (en) | A kind of server-side topological data conversion method and conversion equipment | |
CN107479866A (en) | The method that open terminal applies data and function are realized based on reconfiguration technique | |
CN116795859A (en) | Data analysis method, device, computer equipment and storage medium | |
CN112860584B (en) | Workflow model-based testing method and device | |
CN106610838A (en) | Method for converting multiple script languages | |
CN109062875A (en) | A kind of end C/S three-dimensional modeling data conversion method, device and storage medium | |
CN106293862A (en) | A kind of analysis method and device of expandable mark language XML data | |
CN114115900B (en) | Script compiling method and device and electronic equipment | |
Pérez-Castillo et al. | ANDRIU. A Technique for Migrating Graphical User Interfaces to Android (S). | |
CN115269806A (en) | Question-answering method, electronic device and storage medium applied to mineral domain knowledge graph |
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 |