User Tools

Site Tools


lua:custom_libraries

Libraries

Since version 3.2 you can create your own libraries. These are special scripts that can be included from other scripts so you can share the same code across multiple scripts.

common.lib
function myCommonFunction()
    TRACE("Hello, WebHMI user");
end
COMMON_CONSTANT = 1.6180339887

Use special keyword include to include another script. Provide script title as parameter to include needed script. Here is example:

using_include
include "common.lua"
function main(userId)
  myCommonFunction();
  TRACE("COMMON_CONSTANT = " .. COMMON_CONSTANT)
end

Best practice it is to put include outside any function calls, such as main or etc. Please note, that global variables in libraries will not be shared across all scripts. Only constants and code will be shared.

lua/custom_libraries.txt ยท Last modified: 2021/07/22 07:44 by atolstov

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki