Sample Lua Text Scripts

<< Click to Display Table of Contents >>

Navigation:  Albion 6 GIS User Guide > Appendix > APPENDIX A: Scripting in Albion GIS >

Sample Lua Text Scripts

The following samples demonstrate how to write scripts in Lua. Such scripts are typically used to create GIS labels.

 

Format


All of the samples assume that the script is operating on a database record with the following fields and values:

distribution_zone

original_diameter

diameter

material

code

983

0.200

0.150

PVC

HC203

 

Examples


 

Show 'abc':

return "abc"


abc


 

Show 12 * 3:

return 12 * 3


36


 

Show 'abc ' joined to 12 * 3 (this will produce abc36):

return "abc" .. (12 * 3)


abc36


 

Show 'yes' if original_diameter equals 0.2, otherwise 'no':

if record.original_diameter == 0.2 then return "yes"

else return "no"

end


yes


 

Show A, B, C on 3 lines:

return "A" .. "\n" .. "B" .. "\n" .. "C"


A

B

C


 

If diameter is greater than 0.15, then show material, otherwise show 'narrow':

if record.diameter > 0.15 then return record.material

else return "narrow"

end


narrow


 

If current diameter is greater than original diameter, then show 'expanded', otherwise show nothing:

if record.diameter > record.original_diameter then return "expanded"

else return nil

end


(no text object is generated when you return nil or an otherwise empty result)


 

Use your own variables as temporary placeholders:

local x = record.material

if record.diameter >= 0.15 then

 x = record.material .. '!'

end

x = x .. '\n' .. record.code

return x


PVC!

 

HC203


 

Format sin( 45° ) to 4 significant digits:

-- The trigonometric functions take parameters in radians, not degrees

local v = math.sin( math.rad(45) )

return string.format( "%.4g", v )


 

0.7071


 

Format log10( 1234 ) to 3 digits after the decimal point:

v = math.log10( 1001 )

return string.format( "%.3f", v )


3.091


 

Show material -- code:

return record.material .. "--" .. record.code


PVC -- HC203


 

Show average of original and current diameters:

return (record.original_diameter + record.diameter) / 2.0


0.175


 

Text with double quotes in it:

return 'this is "quoted"'


this is "quoted"


 

Text with single quotes in it:

return "this is 'quoted'"


this is 'quoted'