Recent Changes - Search:


Users


Developers

edit SideBar

LuaScript

Each LuaScript operates on the range of data selected in the current document. As soon as a byte of data is read, execution moves to the next segment of data. The script automatically stops running when all selected data has been processed.

Important Gotcha: Due to technical limitations, all functions that return boolean must be checked explicitly against the value 1.
Invalid: if hf:hasInt( 64 ) then
Valid: if hf:hasInt( 64 ) == 1 then

LuaScript examples


See the Lua Manual for information on general Lua scripting. All core Lua libraries are enabled in Hex Fiend.

Script State Functions


nil setLittleEndian( bool littleEndian )
defaults to little endian
All data processing functions proceding this call will treat bytes as Little Endian or Big Endian.

Data Processing Functions


number hf:getUInt( number bits )
Returns an unsigned number from up to the next 64 bits.

number hf:getSInt( number bits )
Returns a signed number from up to the next 64 bits.

number hf:getFloat()
operates on 4 bytes

number hf:getDouble()
operates on 8 bytes

Data Traversal Functions


nil hf:skip( number bits )
Move the LuaScript cursor ahead by bits bits.

boolean hf:hasInt( number bits )
Returns true if there is enough data to read another integer of size bits.

boolean hf:hasFloat()
Returns true if there is enough data to read another 4-byte float number.

boolean hf:hasDouble()
Returns true if there is enough data to read another 8-byte double number.

Data Manipulation Functions


int hf:OR( number a, number b )
Returns a bitwise OR between a and b (a | b)

int hf:XOR( number a, number b )
Returns a bitwise XOR between a and b (a ^ b)

int hf:AND( number a, number b )
Returns a bitwise AND between a and b (a & b)

int hf:LSH( number a, number bits )
Returns a bitwise-shifted left bits bits (a << bits)

int hf:RSH( number a, number bits )
Returns a bitwise-shifted right bits bits (a >> bits)

Text Output Functions


nil hf:print( string )
Output a string of text, optionally formatted with printf-style flags. For more information, view the Lua manual's section on Lua string operations
Example: hf:print( "Hello world!\n" );
Example: hf:print( ("32-bit Unsigned Integer: 0x%d (1+1=0x%0x)\n"):format( hf:getUInt(32), 2 ) );

Image Output Functions


nil plotWidth( number width )
defaults to 64
Sets the pixel output buffer's width to width. All proceeding plot commands will wrap around this buffer width.

nil plotRGB8( number color [, number x, number y] )
Plot a single pixel at coordinates x, y in the pixel output buffer, of color color. Pixel color is defined as 3 bytes packed within an unsigned number, in the format 0x00RRGGBB. If x is greater or equal to the width set with plotWidth, it will be clamped to plotWidth-1. If x and y are not specified, pixel coordinate is defined as 0,0 if no plotting has taken place, or one pixel to the right of the previously plotted pixel. Pixels that wrap over the right edge of the buffer loop down to the left of the next row.
Example: plotWidth( 0xFF0000, 15, 15 ); -- Plot red pixel at 15,15
Example: plotWidth( 0x0000BB ); -- Plot blue pixel at next pixel raster position

Edit - History - Print - Recent Changes - Search
Page last modified on July 01, 2007, at 08:50 PM