External Code & External Library
External Code & External Library
With this short tutorial, you learn how to insert your own lua library into Kwik.
for isntance, mylibrary.lua just prints out what layers are included in a page
local _M = {}
_M.print = function(layer)
for k,v in pairs(layer) do
print (k)
end
end
return _M
mydebug.lua is just to print myLib.print(layer) passing layer to the parameter. The layer is a table which collects each display object generated from photoshop layer
and then external code - mydebug.lua uses mylibrary to execute the print function. It is just one line code.
myLib.print(layer)
you can find mylibrary.lua and mydebug.lua in the following zip.
https://www.kwiksher.com/tutorials/Kwik4/Recording.zip
Add External Library
From Project&Properties, click Add External Library

Then click + icon

Select mylibrary.lua and name it as myLib

Add External Code
Project and Pages > Add External Code

mydebug.lua is selected

- Name: mydebug
- After layers is selected.
Layer life cycle is like this. Because of some internal process of Kwik, please notice the location of After layers is just before making display objects.
- composer.create
- Before layers to process the external codes
- variable settings for example, mult-language project, it sets the language code with the current selection.
- After layers to process the external codes
- new display objects
- buttons are created
- composer.show
- After buttons and actions to process the external codes
- showing up the objects
- timers are fired
- composer.hide
- Dispose to process the external codes
- hiding the objects
- composer.destroy
- destroy cancel timers/animation
Now you know how to extend Kwik generated lua files with your own codes. When you modify your lua files, you need to click Publish icon to update.
- The published lua file is build4/components/page01/page_ext_lib_code_.lua
- It could be easier that you may edit tmplt/components/pageXXX/page_ext_lib_code_.lua to insert your codes without using Add external code from Kwik Panel. But this method you need to take care of the page number and your codes. Page number is UI.CurPage