[JW Lua] SetPageSize script

Jari Williamsson jari.williamsson at mailbox.swipnet.se
Fri Sep 27 20:25:57 CEST 2013


On 2013-09-27 16:06, Charles O. Lawrence wrote:
> It took
> me some fiddling to get the right syntax to retrieve the table values within
> a table, but it is similar to other programing languages I have used.  Is
> there another syntax you suggest?

Personally, I would prefer to have the table with the sizes in a 
separate variable, specially since you reference it twice, such as:
---
sizetable = selectPageSize[returnValues[1]]
width = sizetable[1]
height = sizetable[2]
---

This approach becomes even more apparent if you expand the table, to 
include the stuff like margins that is part of Finale's pagesizes.txt file.

The cool thing here is the if you implement things such as margins for 
your table, these option can be made optional. Let's say that you have 
"leftmargin = sizetable[3]" - if leftmargin is nil, don't set the value. 
(If you get lots of set-only-if-not-nil values, put that code in a small 
function to get much nicer code.)

> I sorted the popuplist table, since the
> dropdown was not in the same order as the table was initialized.

Ok, so it was as I suspected. It's the nature of a Lua table to not 
assume that added elements are at the end of a table. In that aspect Lua 
tables behaves differently compared to an array or a collection.

Btw, if you want to have fun with Lua, try to add a custom sort (for 
example, sort by page size) of your table as an inline function without 
a name directly as the 2nd parameter in the table.sort() call.


Best regards,

Jari Williamsson






More information about the JWLua mailing list