Child pages
  • IP Editor
Skip to end of metadata
Go to start of metadata

This is a sub-class of Widget. A IPEditor allows the user to input an IP address.

Constructor

mgf.createIPEditor()

Fields

FieldTypeDescriptionRead/Write
value

Number

This contains the value of the IP address.Read / Write

Examples 

In this example the IPEditor is used inside a Dialog. Of course using the Dialog is optional.

Notice how the IP value can be converted to a buffer using bit operations!

Example: IPEditor with Dialog
-- Function to convert IP buffer to 32 bit value
function IPbufferToValue( )
  val = buf[4]
  val = bit.bor( val, bit.lshift( buf[3], 8  ) )
  val = bit.bor( val, bit.lshift( buf[2], 16 ) )
  val = bit.bor( val, bit.lshift( buf[1], 24 ) )
  return val
end
 
-- Function to convert 32 bit value to IP buffer
function valueToIPbuffer( val )
  buf[4] = bit.rshift( bit.band( IPEditor.value, 0x000000FF ), 0  )
  buf[3] = bit.rshift( bit.band( IPEditor.value, 0x0000FF00 ), 8  )
  buf[2] = bit.rshift( bit.band( IPEditor.value, 0x00FF0000 ), 16 )
  buf[1] = bit.rshift( bit.band( IPEditor.value, 0xFF000000 ), 24 )
end
 
-- Create IPEditor Widget
IPEditor = mgf.createIPEditor()
 
-- Set IP value to 192.168.1.80
buf = buffer.create( 4 )
buf[4] = 192
buf[3] = 168
buf[2] = 1
buf[1] = 80
IPEditor.value = IPbufferToValue()
 
-- Add the IPEditor to a dialog
dialog = mgf.createDialog( IPEditor, "Input an IP", mgf.ModeOKCancel )
 
-- Create an actionListener for the dialog
dialog.actionListener  = function ( widget, action )
  print( "Action: ", action )
  
  valueToIPbuffer( IPEditor.value )
 
  print( "IP: " .. buf[4] .. "." .. buf[3] .. "." .. buf[2] .. "." .. buf[1] )
end
  
mgf.setWidget( dialog )

 


  • No labels