Home > HMS NETWORKS > HMS NETWORKS CANbridge NT Lua ADK Bridge Router User Guide
HMS NETWORKS CANbridge NT Lua ADK Bridge Router User Guide
CAN@net NT/CANbridge NT Lua ADK
Specics in Coding for the Ixxat Lua ADK
In standard Lua all variables can be classied as globalsor locals. By default, any variable that is referenced
and not previously declared as localis global. Global variables persist in the global table unl the variable is
explicitly deleted.
To see what global variables are in scope, use the following command:
for k,v in pairs(_G) do print(k,v) end
Local variables are lexically scoped. This means the scope of local variables is limited to the block where they
are declared. A block is the body of a control structure, the body of a uncon or a chunk (the le or string
with the code where the variable is declared). Any variable can be declared localwithin nested blocks or
uncons without aecng the enclosing scope. Because locals are lexically scoped it is also possible to refer to
local variables in an outer scope. These variables are sll accessible within the inner scope.
The Lua runme internally uses hashed key access to retrieve keyed data from a table. Locals are stored as
a conguous vector and are accessed directly by an index, which is faster. Access to rmware based tables is
parcularly slow.
Using locals as follows is both a lot faster at runme and generates less byte code insrucons for their access:
local can_send = can.send
2.4.4. Passing Context between Lua Event Tasks
A single Lua uncon is bound to any event callback task. The uncon is executed from within the relevant
C code using a lua_call(). Each uncon can invoke other uncons and so on. But each uncon must
ulmaely return the control to the C library code which then returns the control to the rmware.
Lua local variables that are dened inside a uncon only exist within the context of this execung Lua uncon.
Therefore locals are unreferenced on exit and any local data and garbage might be collected between the
lua_call()acons.
Context can be passed in two ways between event tasks:
• by global variables: any global variable persists unl it is explicitly dereferenced by assigning nilto the
variable.
• by local variables: local variables that are dened in an outer scope (see descripon of locals in Declaring
Variables, p. 3).
Page 4 of 20
4.02.0332.20002 Version 1.5
| General | Details |
|---|---|
| Name | HMS NETWORKS CANbridge NT Lua ADK Bridge Router User Guide |
| Make | HMS NETWORKS |
| Language | English |
| Filetype | PDF (Download) |
| File size | MB |
If you have any questions regarding HMS NETWORKS CANbridge NT Lua ADK Bridge Router User Guide, please ask here and describe the problem in detail.













