"Q" Original 2015-08-30
The company has been using Cocos2dx+lua to develop the game for some time, just as the thermal update of LUA is entrusted to me. Most of the previously hot-updated LUA scripts were loaded after the download. Recent planning and new requirements, need to be in the game process if there is a hot update to remind users, also means that the in-memory LUA files may not be up-to-date. Later http://www.2cto.com/kf/201411/351833.html this blog found that Lua was originally loaded into a package.loaded cache, as long as the corresponding set this to empty and require.
Later also in accordance with the idea of the blog also want to implement a one-click Reload all LUA files, to solve the problem of starting the emulator every time. The overall implementation is possible because of the Mac simulator that the project is using during the development process. The project registers a key event in a major scenario. This time I used the ctrl+r combination to achieve.
Code I also do not post, mainly is the method of the blog, but there are changes,
1, the external library register to add more libraries, such as Protobuf, string, math and so on.
2, for the external library, we do not think that the modification, so the processing of the external library display does not reload.
3, for the framework of files, such as cococs2d files, we think in the development process will not be modified, so in filtering some of this file.
4. Since all LUA files have been reloaded, the corresponding sockets will also be disconnected before.
5. Empty all the memory textures.
In practice, the development is accelerated because there is no need to restart the emulator. Thanks to this blog author for his enthusiastic sharing.
COCOS2DX LUA Hot Load implementation