Lua dynamic Fix online bug practice (iOS)

Source: Internet
Author: User

lua dynamic Fix online bug Practice (iOS)

using the wax framework, wax cancombine the LUA scripting language with the native OBJECTIVE-C application programming Interface (API). This means that you can use any and all of the objective-c classes and frameworks from within Lua.1.wax.framework problem Https://github.com/probablycorey/wax This framework has not been updated for 4 years, and does not support 64-bit. Use it to replace the original Viewcontroller function does not take effect. So replace with https://github.com/maxfong/WaxPatch_X64

2. Pull the wax frame in or out of operation, error
It can be seen that the wrong meaning isTcpservererrordomain This flag is defined repeatedly in wax and wax_server,Solution: Note the Tcpservererrordomain in the wax_server.


3. Test to fix bugs dynamically.To change the color of a page as an example, originally displayed as white, and now the version is sent out, I want to change the color to red (1) each time you launch the app, create a dynamically loaded Lua file entry (write below) and start the Lua file:Wax_start("Change.lua", nil);(2) the page originally has a method:- (void) setbackgroundcolor{ NSLog (@ "Test"); }If you do not have this method to hook other methods, then use LUA to write the same implementation and add a change in the background color method.(3) How to write Change.lua color change: waxclass{"Viewcontroller", Uiviewcontroller} functionsetbackgroundcolor (self) Self:view (): SetBackgroundColor (Uicolor:redcolor ())End
(4) Ok, the SetBackgroundColor method has been replaced by the Lua modified method when running


4. Creating a portal to dynamically load LUA files- (BOOL) Application: (uiapplication*) Application didfinishlaunchingwithoptions: (nsdictionary*) Launchoptions {
[ SelfDownloadluafile];
Return YES;
}

- (void) Downloadluafile {
Dispatch_async(Dispatch_get_main_queue(), ^{       NSString*doc = [Nssearchpathfordirectoriesindomains(nsdocumentdirectory,Nsuserdomainmask,YES)Objectatindex:0];       NSString*directory = [Doc stringbyappendingpathcomponent:@ "Change.lua"];        Nsurl *url=[Nsurlurlwithstring:@ "Http://localhost/change.lua"];
nsurlrequest *request=[nsurlrequestRequestwithurl: URL];
Nserror *error=nil;
NSData *data = [nsurlconnectionsendsynchronousrequest: RequestReturningresponse: NilError:&error];
if ([Data length]>0)
{
NSLog(@"Download Successful");
if ([Data WriteToFile:d irectoryatomically:YES]){               NSLog(@"saved successfully");                nsstring *luafilepath = [[ nsstring alloc initwithformat : @ "%@/?. Lua;%@/?/init.lua;%@/?. DAT; " ,doc, Doc,doc]; setenv(lua_path, [Luafilepathutf8string], 1 ); I almost missed it. Set path                 Wax_start("Change.lua", nil);
}else {
NSLog(@"Save failed");
}
} else {
NSLog(@"download failed, reason for failure:%@", error);
}
});}

5. Then a bug in the online version can be fixed in the issued Change.lua file.
6. What if there is a more complex bug? Learn more about LUA and theoretically what bugs can be fixed.

Lua dynamic Fix online bug practice (iOS)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.