alibaba / wax

Wax is a framework that lets you write native iPhone apps in Lua.
http://github.com/probablycorey/wax
MIT License
1.84k stars 280 forks source link

How can I update my lua script while app is running? #40

Closed itliming closed 5 years ago

itliming commented 8 years ago

Hi,here is my problem: I use the method "wax_start" to init wax,just like this: NSString doc = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSString dir = [doc stringByAppendingPathComponent:@"lua"];

NSString *pp = [[NSString alloc ] initWithFormat:@"%@/?.lua;%@/patch/?.lua;", dir, dir];
setenv(LUA_PATH, [pp UTF8String], 1);
wax_start("patch", nil);

"patch" is a lua file named patch.lua , require "MainViewController" require "SecondViewController"

MainViewController.lua: waxClass{"MainViewController", UIViewController}

function viewDidLoad(self)

self:ORIGviewDidLoad(self)
self:addDeletePatchButton(self)

end

function setBackGroundColor(self) self:view():setBackgroundColor(UIColor:yellowColor()) end

function addDeletePatchButton(self) local deletebutton = UIButton:buttonWithType(UIButtonTypeCustom) deletebutton:setFrame(CGRect(100, 300, 200, 100)) deletebutton:setTitle_forState("second",UIControlStateNormal) deletebutton:setTitleColor_forState(UIColor:blueColor(),UIControlStateNormal) deletebutton:addTarget_action_forControlEvents(self,"second",UIControlEventTouchUpInside) self:view():addSubview(deletebutton) end

function second(self) local secondController = SecondViewController:init() self:presentViewController_animated_completion(secondController,YES,nil) end

SecondViewController.lua: waxClass{"SecondViewController", UIViewController} function viewDidLoad(self) self:setBackGroundColor(self) self:addDeletePatchButton(self) end

function setBackGroundColor(self)

self:view():setBackgroundColor(UIColor:greenColor())

end

function addDeletePatchButton(self)

local deletebutton = UIButton:buttonWithType(UIButtonTypeCustom)
deletebutton:setFrame(CGRect(100, 300, 200, 100))
deletebutton:setTitle_forState("updatedback7",UIControlStateNormal)
deletebutton:setTitleColor_forState(UIColor:blackColor(),UIControlStateNormal)
deletebutton:addTarget_action_forControlEvents(self,"updatedback",UIControlEventTouchUpInside)

self:view():addSubview(deletebutton)

end

function updatedback(self) self:dismissViewControllerAnimated_completion(YES,nil) end

Now I want to update the code of MainViewController.lua,to change the action of function "second" ,so I download the new MainViewController.lua file from Server ,How can I make the new file work?

intheway commented 8 years ago

after the files updated, you can use wax_runLuaFile to run the file again.