Library manager menu items

Guest
Hi,

I've been trying to add menu items to the library manager
programmatically with something like the following:

menuLabel = "Menu Label"
(lmgrCreateMenuItem menuName "simple" '(("label" menuLabel) ("callback" ("menuCallback"))))

This gives an error:

*Error* lmgrCreateMenuItem: label must have a string
value - ("label" menuLabel)

Is there any way round this, or do I have to write out the strings as
static strings?

Thanks,

Roger
 
On 2009-01-13, Roger Light <roger.light@nospamnottingham.ac.uk> wrote:
menuLabel = "Menu Label"
(lmgrCreateMenuItem menuName "simple" '(("label" menuLabel) ("callback" ("menuCallback"))))
Answering my own questions again, the correct way to do this is
something like:

attributes = (list (list "label" menuLabel) (list "callback" (list
"menuCallback")))
(lmgrCreateMenuItem menuName "simple" attributes)

Cheers,

Roger
 
Roger Light wrote, on 01/13/09 15:37:
On 2009-01-13, Roger Light <roger.light@nospamnottingham.ac.uk> wrote:
menuLabel = "Menu Label"
(lmgrCreateMenuItem menuName "simple" '(("label" menuLabel) ("callback" ("menuCallback"))))

Answering my own questions again, the correct way to do this is
something like:

attributes = (list (list "label" menuLabel) (list "callback" (list
"menuCallback")))
(lmgrCreateMenuItem menuName "simple" attributes)

Cheers,

Roger
Hi Roger,

That's right, you have to ensure that the variable menuLabel is being evaluated.
In your first case it wasn't, so it was just seeing the symbol menuLabel. You
could make the code a little more readable by judicious use of the backquote
operator:


menuLabel = "Menu Label"
(lmgrCreateMenuItem menuName "simple"
`(("label" ,menuLabel) ("callback" ("menuCallback"))))

The backquote operator allows a list to be quoted, everywhere except where a
variable is preceded with either , (as above) or ,@ (for list splicing).

See my previous treatise on macros for more details on backquotes:

http://tinyurl.com/7epjjk

Regards,

Andrew.
 
On 2009-01-13, Andrew Beckett <andrewb@DcEaLdEeTnEcTe.HcIoSm> wrote:

That's right, you have to ensure that the variable menuLabel is being evaluated.
In your first case it wasn't, so it was just seeing the symbol menuLabel. You
could make the code a little more readable by judicious use of the backquote
operator:


menuLabel = "Menu Label"
(lmgrCreateMenuItem menuName "simple"
`(("label" ,menuLabel) ("callback" ("menuCallback"))))

The backquote operator allows a list to be quoted, everywhere except where a
variable is preceded with either , (as above) or ,@ (for list splicing).
Ah, very handy and much more readable like you say (although less
obvious to the untrained eye, alas).

See my previous treatise on macros for more details on backquotes:

http://tinyurl.com/7epjjk
Well worth bookmarking! As another point of reference, the details on
the backquote and comma notation for lists is in sklanguser in the
section "Backquote, Comma and Comman-At.

Cheers,

Roger
 

Welcome to EDABoard.com

Sponsor

Back
Top