Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
In the following, embodiments of the present application will be described, and then experimental data will be used to confirm what different and advantageous effects can be achieved in the scheme of the present application compared with the prior art.
Referring to fig. 1, a flowchart of an embodiment of a method for capturing an lua code exception according to the present application is shown, where the method for capturing an lua code exception according to the present embodiment may be applied to an APP (application program) containing an lua code.
As shown in fig. 1, in step 101, it is set that the lua code is called by an exception handling function each time the lua code is called;
then, in step 102, obtaining the return value of the exception handling function and pushing the return value of the exception handling function to the lua stack;
finally, in step 103, if the lua code is abnormal, the application language function is called backward to pass the error information in the lua stack to the application language function.
In this embodiment, for step 101, the means for trapping the lua exception first wraps the lua code with an exception handling function so that each time the lua code is called, it is called by the exception handling function. In some alternative embodiments, the exception handling function includes lua _ pcall and lua _ xpcals. Thereafter, for step 102, the means for catching the lua exception obtains a return value of the exception handling function and pushes the return value into the lua stack, where the return value of the exception handling function at least includes whether the lua code is abnormal, such as true or false, or true or nil, and a return value when the lua code is normal or error information when the lua code is abnormal. In a further embodiment, additional information or extension information of the error information may also be included, such as descriptive information of the error information or the like. Finally, for step 103, if a code exception is raised from the return value in the lua stack, the application language function is called backward to pass the error information in the lua stack to the application language function. The language function can be a java function, a C/C + + function, a Python function or other functions for writing APP so as to transfer errors from the bottom layer to the application layer.
According to the method, the lua code is called by using the exception handling function, and then the exception is transmitted to the application language function, so that even if the lua code is broken down due to an error, the exception handling function cannot be broken down, and error information is placed on the lua stack and transmitted. Therefore, developers can acquire error information of the lua layer at the first time no matter in the process of app development or after the app is formally released and used, error scenes with very small probability can be timely positioned, and the error scenes can be timely repaired.
With further reference to FIG. 2, shown is a flow diagram of another method of the present application for catching lua code exceptions.
As shown in fig. 2, in step 201, the error information captured by the application language function is thrown to the upper layer;
in step 202, error information thrown by the application language function is captured and uploaded at the upper layer.
In this embodiment, for step 201, the means for trapping the lua code exception throws an error message received by the application language function for the lua code passed by the lua stack to the upper layer. Then, in step 202, the error information thrown by the application language function is captured at the upper layer and uploaded to the server of the APP, so that the server can know the abnormality of the lua in real time.
With further reference to FIG. 3, shown is a flow diagram of yet another method of the present application of catching lua code exceptions. The flow is mainly a refinement step to step 101 in fig. 1.
As shown in FIG. 3, in step 301, the lua code is encapsulated in a preset function;
in step 302, the calling lua code is modified to call a preset function through an exception handling function.
In this embodiment, for step 301, the means for catching the lua code exception encapsulates the lua code in a preset function. Thereafter, for step 302, the means for trapping the lua code exception modifies the instruction calling the lua code to call a predetermined function through an exception handling function, for example, by modifying a pointer pointing to the predetermined function calling the lua code to point to an exception handling function (e.g., lua _ pcall). Therefore, the error-prone lua code can be packaged, and even if the lua code is in error and crashes, capture of the exception by the exception handling function is not influenced.
The following presents a brief description of the lua and the interaction between the lua and other languages to enable those skilled in the art to better understand the concepts of the present application.
lua is an extended programming language designed to support general purpose procedural programming and has associated data description facilities. And simultaneously, good support is provided for object-oriented programming, functional programming and data-driven programming. To summarize, lua is a lightweight language and supports multiple programming paradigms, with any desirable adaptation of the language.
As an extension language, lua has no notion of a "main" program, and can only work embedded in a host program, which is called an embedded program or simply a host. The host program can call a function to execute a small lua code, read and write lua variable, and register the C function to make the lua code call.
The lua program does not generally run separately, but it is simpler to do so, although it is also possible. The standard lua virtual machine is written through C language, and the function of the lua is generally expanded through C/C + +, so that the interface compatibility speed is higher.
The stack of lua is highlighted here for convenience of description later.
The data exchange between the lua virtual machine and the C/C + + is basically interactive through constructing a virtual stack by the lua, and whenever the lua calls the C, the called function obtains a new stack which is independent of the stack of the C function and the previous lua stack. It contains all the parameters that the lua passes to the C function, which puts the result to be returned on the stack for return to the caller.
Based on the characteristic of the lua as "parasitic work", the idea of mutual calling between Java and lua languages is obvious, that is, jni (Java Native Interface) is used as an intermediary.
In order to solve the above-mentioned drawbacks of the prior art, some products of the prior art may be solved by the following methods:
after the general app crashes, the system layer may retain some crash information, and after the app is started again, the crash information may be sent to the background server.
The inventors have discovered that, first, this approach requires the operating system level to be able to save crash information, which is not supported by all systems; secondly, the app needs to read the log related to the app from the system; finally, the app itself needs to have a server capable of receiving and storing these logs, which is a very large project.
The method provided by the embodiment of the application ensures that the effective log can be captured certainly by the following method and uploaded to the server. Specifically, refer to fig. 4, which shows a schematic diagram of an anomaly capture process according to an embodiment of the present application. It should be noted that, although the embodiment is only given in which the exception handling function is lua _ pcall and the application language function is java function in this embodiment, the present disclosure is not limited to this embodiment, and those skilled in the art may obtain other combination schemes according to the following embodiments, and details are not described herein again.
1) Functions such as lua _ pcall and pcall are adopted to run the lua code, so that the lua is not crashed in the C layer in the running process, and the application is not crashed even if errors occur;
2) after the lua layer makes an error, reversely calling java codes at the C layer and carrying out a throw exception to the java layer;
3) capturing abnormal information by a java layer;
4) uploading the exception information to the server through the busy tool of Tencent.
As shown in figure 4 of the drawings,
1) each time the lua code is called in the android, the lua code is called through the lua _ pcall, and the function does not crash when the lua code goes wrong, but the error information is put on the lua stack.
2) Judge whether each call is in error by the return value of lua _ pcall (has errors? ) And if no error exists, returning to the step 1) and continuing to execute.
3) If an error occurs, the java function (call java function) is called reversely through the jni function, and when the call is carried out, the error information on the lua stack is transmitted to the java function at the same time.
4) And (4) throwing an exception (throw exception) to an upper layer in the java function, wherein exception information is error information of the lua.
5) An android bug tool provided by some Internet company is simultaneously run in the android app, and the tool can capture exception (catch exception) thrown by java functions.
6) after capturing the exception, the android bugly is uploaded to a bug server (send to server) through the network.
Therefore, exception capture and uploading of lua are completed completely, and android developers can check error information uploaded by the app and repair the error information in time by logging in the bugly server every day.
According to the scheme, developers can acquire error information of the lua layer at the first time no matter in the app development process or after the app is officially released and used, error scenes with very small probability can be timely positioned, and the error scenes can be timely repaired.
Referring to fig. 5, a block diagram of an apparatus for trapping an lua code exception according to an embodiment of the present invention is shown.
As shown in FIG. 5, the apparatus 500 for trapping an lua code exception according to the present invention includes a setting module 510, a return value processing module 520, and a passing module 530.
Wherein the setting module 510 is configured to set that the lua code is called by an exception handling function each time the lua code is called; a return value processing module 520, configured to obtain a return value of the exception handling function and push the return value of the exception handling function to the lua stack, where the return value of the exception handling function at least includes whether the lua code is abnormal or not, and a return value when the lua code is normal or error information when the lua code is abnormal; and a pass module 530 configured to call the application language function backwards to pass error information in the lua stack to the application language function if the lua code is abnormal.
In some optional embodiments, the apparatus 500 for trapping lua code exception further includes an error throwing module (not shown in the figure) and a trapping uploading module (not shown in the figure). The error throwing module is configured to throw the error information captured by the application language function to an upper layer; and the capturing and uploading module is configured to capture and upload error information thrown by the application language function.
In some optional embodiments, the setup module 510 further includes an encapsulation module and a call modification module. The encapsulation module is configured to encapsulate the lua code in a preset function; and a call modification module configured to modify the call lua code to call the preset function through the exception handling function.
It should be understood that the modules recited in fig. 5 correspond to various steps in the methods described with reference to fig. 1, 2, and 3. Thus, the operations and features described above for the method and the corresponding technical effects are also applicable to the modules in fig. 5, and are not described again here.
It is to be noted that the modules in the embodiments of the present disclosure are not intended to limit the scheme of the present disclosure, and for example, the setting module may be described as a module that sets the lua code to be called by the exception handling function each time the lua code is called. In addition, the related functional modules may also be implemented by a hardware processor, for example, the setting module may also be implemented by a processor, which is not described herein again.
In other embodiments, an embodiment of the present invention further provides a non-volatile computer storage medium, where the computer storage medium stores computer-executable instructions, and the computer-executable instructions may perform the method for capturing the lua code exception in any of the above method embodiments;
as one embodiment, a non-volatile computer storage medium of the present invention stores computer-executable instructions configured to:
setting that the lua code is called through an exception handling function each time the lua code is called;
obtaining a return value of the exception handling function and pushing the return value of the exception handling function to an lua stack, wherein the return value of the exception handling function at least comprises whether the lua code is abnormal or not and the return value when the lua code is normal or error information when the lua code is abnormal;
if the lua code is abnormal, an application language function is called reversely to transfer error information in the lua stack to the application language function.
As a non-volatile computer readable storage medium, it can be used to store non-volatile software programs, non-volatile computer executable programs, and modules, such as program instructions/modules corresponding to the method for capturing lua code exception in the embodiment of the present invention. One or more program instructions are stored in a non-transitory computer readable storage medium, which when executed by a processor, perform a method of trapping lua code exceptions in any of the method embodiments described above.
The non-volatile computer-readable storage medium may include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required for at least one function; the storage data area may store data created from use of a device that captures an lua code exception, and the like. Further, the non-volatile computer-readable storage medium may include high speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other non-volatile solid state storage device. In some embodiments, the non-transitory computer readable storage medium optionally includes memory located remotely from the processor, which may be connected over a network to the means for catching the lua code exception. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
Embodiments of the present invention also provide a computer program product comprising a computer program stored on a non-transitory computer readable storage medium, the computer program comprising program instructions which, when executed by a computer, cause the computer to perform any of the above methods of catching lua code exceptions.
Fig. 6 is a schematic structural diagram of an electronic device according to an embodiment of the present invention, and as shown in fig. 6, the electronic device includes: one or more processors 610 and a memory 620, with one processor 610 being an example in fig. 6. The apparatus of the method of trapping an lua code exception may further include: an input device 630 and an output device 640. The processor 610, the memory 620, the input device 630, and the output device 640 may be connected by a bus or other means, such as the bus connection in fig. 6. The memory 620 is a non-volatile computer-readable storage medium as described above. The processor 610 executes various functional applications of the server and data processing by running nonvolatile software programs, instructions and modules stored in the memory 620, that is, implements the method for capturing the lua code exception of the above method embodiment. The input device 630 may receive input numeric or character information and generate key signal inputs related to user settings and function controls of the information delivery device. The output device 640 may include a display device such as a display screen.
The product can execute the method provided by the embodiment of the invention, and has corresponding functional modules and beneficial effects of the execution method. For technical details that are not described in detail in this embodiment, reference may be made to the method provided by the embodiment of the present invention.
As an embodiment, the electronic device is applied to a neural network language model, and includes: at least one processor; and a memory communicatively coupled to the at least one processor; wherein the memory stores instructions executable by the at least one processor to cause the at least one processor to:
setting that the lua code is called through an exception handling function each time the lua code is called;
obtaining a return value of the exception handling function and pushing the return value of the exception handling function to an lua stack, wherein the return value of the exception handling function at least comprises whether the lua code is abnormal or not and the return value when the lua code is normal or error information when the lua code is abnormal;
if the lua code is abnormal, an application language function is called reversely to transfer error information in the lua stack to the application language function.
The electronic device of the embodiments of the present application exists in various forms, including but not limited to:
(1) a mobile communication device: such devices are characterized by mobile communications capabilities and are primarily targeted at providing voice, data communications. Such terminals include smart phones (e.g., iphones), multimedia phones, functional phones, and low-end phones, among others.
(2) Ultra mobile personal computer device: the equipment belongs to the category of personal computers, has calculation and processing functions and generally has the characteristic of mobile internet access. Such terminals include: PDA, MID, and UMPC devices, etc., such as ipads.
(3) A portable entertainment device: such devices can display and play multimedia content. Such devices include audio and video players (e.g., ipods), handheld game consoles, electronic books, as well as smart toys and portable car navigation devices.
(4) The server is similar to a general computer architecture, but has higher requirements on processing capability, stability, reliability, safety, expandability, manageability and the like because of the need of providing highly reliable services.
(5) And other electronic devices with data interaction functions.
The above-described embodiments of the apparatus are merely illustrative, and the units described as separate parts may or may not be physically separate, and the parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment. One of ordinary skill in the art can understand and implement it without inventive effort.
Through the above description of the embodiments, those skilled in the art will clearly understand that each embodiment can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware. With this understanding in mind, the above-described technical solutions may be embodied in the form of a software product, which can be stored in a computer-readable storage medium, such as ROM/RAM, magnetic disk, optical disk, etc., and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the methods of the various embodiments or some parts of the embodiments.
Finally, it should be noted that: the above examples are only intended to illustrate the technical solution of the present invention, but not to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions of the embodiments of the present invention.