CppFBP/Lua Interface

Supported services

retcode, IPaddr = dfscrep(string)                 -- Create Packet 
retcode, IPaddr, size, type = dfsrecv(portname)   -- Receive  
retcode = dfssend(portname, IPaddr)               -- Send 
dfsdrop(IPaddr)                                   -- Drop Packet
result = dfsderef(IPaddr)                         -- Dereference 
result = dfselct(portname)                        -- Array port element count
retcode = dfsclos(portname)                       -- Close port
retcode = myprint(string)                         -- Print value (for debugging) 

Sample Lua scripts


Generate number of IPs specified in IIP at COUNT port, and send results to OUT

-- gen.lua        
      
value, IPaddr, size, type = dfsrecv("COUNT")

i = dfsderef(IPaddr)
dfsdrop(IPaddr)
print (i)

for j = 1, i do
  value, IPaddr = dfscrep("string"..j)
  --myprint(IPaddr)
  value = dfssend("OUT", IPaddr)
end
return 0
      

Concatenate input streams from successive elements of array port IN, and sends the result to port OUT:

  
      
-- concat.lua
      
i = dfselct("IN");   -- get element count for port "IN"

for i = 0, i - 1 do
   -- receive from element i of port "IN"
  value, IPaddr, size, type = dfsrecv("IN["..i.."]")    
  while value == 0 do           
     value = dfssend("OUT", IPaddr)   -- send IP to port "OUT"
      -- receive from element i of port "IN"                    
     value, IPaddr, size, type = dfsrecv("IN["..i.."]") 
  end
end
      

Replicate incoming IPs to output port array elements OUT[0 - n]

  
      
-- repl.lua

i = dfselct("OUT");   -- get element count for port "OUT"

value, IPaddr, size, type = dfsrecv("IN")  

while value == 0 do 
string = dfsderef(IPaddr)
   for j = 0, i - 1 do
       value, IPaddr2 = dfscrep(string)
	   --myprint(IPaddr2)
       value = dfssend("OUT["..j.."]", IPaddr2) 
   end
   --myprint(IPaddr)
   value = dfsdrop(IPaddr)

   value, IPaddr, size, type = dfsrecv("IN")
end
return 0