<< Click to Display Table of Contents >> Navigation: Multi-Protocol MasterOPC Server > Lua 5.1 Reference Manual > Function library > The SERVER Library > Function Invocation |
server.RunFunctionFromDeviceByName
server.RunFunctionFromNodeByName
server.RunFunctionFromSubDevice
server.RunFunctionFromSubDeviceByName
To call a function defined in the current script, the standard Lua mechanism is used - see Function Calls and Function Definitions. To call functions defined in other scripts (in a script of other node, device or sub-device), the respective extra functions are used.
The following functions can be invoked from a tag script: functions defined in a script of a sub-device, a device or a node.
The following functions can be invoked from a sub-device script: functions defined in a script of a device or a node.
From a device script, functions defined in a node script can be invoked.
Only following method can be used to call external function if a table must be passed to that function: Using the function server.TableToString , a table is previously converted into a string of the special format, That string is passed into the external function where reverse conversion is made, using the function server.StringToTable .
Invokes a function defined in the current device.
Input parameters are: a function name, number of parameters to be returned, and arguments.
Example
res = server.RunFunctionFromDevice("Fun",1,1,"t",true);
--The FUN function is defined in the current device
function Fun(n,t,b)
return "ok"
end
server.RunFunctionFromDeviceByName
Invokes a function defined in arbitrary device.
Input parameters are: a full name of the device, a function name, number of parameters to be returned, and arguments.
Example
res = server.RunFunctionFromDeviceByName("Node2.Device2","Fun",1,1,"t",true);
--The FUN function is defined in arbitrary device
function Fun(n,t,b)
return "ok"
end
Invokes a function defined in the current node.
Input parameters are: a function name, number of parameters to be returned, and arguments.
Example
res = server.RunFunctionFromNode("Fun",1,1,"t",true);
--The FUN function is defined in the current node
function Fun(n,t,b)
return "ok"
end
server.RunFunctionFromNodeByName
Invokes a function defined in arbitrary node.
Input parameters are: a node name, a function name, number of parameters to be returned, and arguments.
Example
res = server.RunFunctionFromNodeByName("Node1","Fun",1,1,"t",true);
--The FUN function is defined in arbitrary node
function Fun(n,t,b)
return "ok"
end
server.RunFunctionFromSubDevice
Invokes a function defined in the current sub-device.
Input parameters are: a function name, number of parameters to be returned, and arguments.
Example
res = server.RunFunctionFromSubDevice("Fun",1,1,"t",true);
--The FUN function is defined in the current sub-device
function Fun(n,t,b)
return "ok"
end
server.RunFunctionFromSubDeviceByName
Invokes a function defined in arbitrary sub-device.
Input parameters are: a full name of the sub-device, a function name, number of parameters to be returned, and arguments.
Example
res=server.RunFunctionFromSubDeviceByName("Node3.Device2.Subdevice1","Fun",1,1,"t",true);
--The FUN function is defined in arbitrary sub-device
function Fun(n,t,b)
return "ok"
end
Converts a string of the special format to a table (see server.TableToString ).
Example
function CRCsum(SFrame)
buf={}; --declare a variable-table
buf=server.StringToTable(SFrame); --converting a received string to a table.
-- If the s string is received (see example in description of
-- the function server.TableToString) then buf={10,20,30,40}
end
Converts a table to a string of the special format.
This function is used to pass tables when invoking external functions (that is, functions defined in a nodes, devices or sub-devices). An external function uses the function server.StringToTable for reverse conversion.
Example
buf={10,20,30,40}; --create a variable-table and fill it with data
s = server.TableToString(buf); --conversion of a table to a string
--Invocation of an external function; a string is passed as an argument:
CRC=server.RunFunctionFromDevice("CRCsum",1,s);
--Reverse conversion must be made in the invoked function