LUA Apps
All LUA functions that are invoked by server tasks as well as all predefined event callbacks are called in the same thread context. This means that these functions are not executed independent of each other – they are executed one by one. Especially if a lot of functionality is implemented in a LUA function i.e. if it contains a lot of LUA code, this may be a disadvantage because a long execution of a LUA function may block other LUA function.
In order to be able to implement time consuming tasks, so called LUA Apps are available. LUA Apps are executed
within a separate thread within the LUA engine. This means that LUA Apps are executed to some extend in parallel without block each other.
LUA Apps are invoked using the following LUA function: https://netxautomation.atlassian.net/wiki/x/coBPO After calling the "nxa.StartApp", the given function is executed as App. If the function is returns, the App is automatically terminated. This means if a LUA App shall be able to do some periodic task, a loop has to be included.
Available nxa functions which can be used safely
Since LUA Apps are invoke in parallel, the implemented functionality and the used resource must be thread-safe i.e. critical operations must be protected. Therefore, only the following functions can be used within LUA Apps (other function could cause unpredictable behaviour and are not safe to use):
nxa.LogInfo
nxa.LogWarning
nxa.LogError
nxa.IsInitialized
nxa.IsRunning
nxa.IsSimulation
nxa.IsActiveServer
nxa.IsMainServer
nxa.IsBackupServer
nxa.GetValue | nxa.Value
nxa.SetValue
nxa.SetItemData
nxa.WriteValue
nxa.ReadValue
nxa.IsValidValue
nxa.WorkspaceName
nxa.RootPath
nxa.WorkspacePath
nxa.ScriptFilesPath
nxa.DataFilesPath
nxa.LogFilesPath
nxa.ProjectFilesPath
nxa.EventFilesPath
nxa.ConfigFilesPath
nxa.GetItemID
nxa.Sleep (only available inside a LUA App)
nxa.Now
nxa.TimeOnly
nxa.DateOnly
nxa.Year
nxa.Month
nxa.Day
nxa.Hour
nxa.Minute
nxa.Second
nxa.DayOfWeek
nxa.MakeDate
nxa.MakeTimeOnly
nxa.AddDate
nxa.DiffDate
nxa.DateToString
nxa.SetDate
nxa.SetTimeOnly
nxa.GetVar
nxa.SetVar
nxa.ClearVar
nxa.AddVarTask
nxa.SourceVar
nxa.GetPropertyValue | nxa.PropertyValue | nxa.Property
nxa.SetPropertyValue | nxa.SetProperty
nxa.GetLastErrorText
nxa.GetLastErrorCode
nxa.LowByte
nxa.HiByte
nxa.LowWord
nxa.HiWord
nxa.IsBitSet
nxa.SetBit
nxa.ResetBit
nxa.SetLowByte
nxa.SetHiByte
nxa.SetLowWord
nxa.SetHiWord
nxa.And
nxa.Or
nxa.Xor
nxa.Tor
nxa.Not