Hi, I encountered a problem with select() in beta-0.40.6-2009100509 (TeX Live 2009): ------------------------------------------------------------------ #! /usr/bin/env texlua print (select (1, string.gsub ('abc', 'b', 'X'))) print (select (2, string.gsub ('abc', 'b', 'X'))) ------------------------------------------------------------------ --> aXc 1 --> 1 This seems to be wrong. select (1, ....) should only return the first argument, not both. I'm wondering why select (2, ....) works as expected. I must admit that I couldn't find any specs for select(), it just appears in some examples in the Lua book. I can define select() myself, overwriting the built-in function. Then I get the results I expect: ------------------------------------------------------------------ #! /usr/bin/env texlua function select (n, ...) return arg[n] end print (select (1, string.gsub ('abc', 'b', 'X'))) print (select (2, string.gsub ('abc', 'b', 'X'))) ------------------------------------------------------------------ --> aXc --> 1 Bug or feature? Regards, Reinhard -- ---------------------------------------------------------------------------- Reinhard Kotucha Phone: +49-511-3373112 Marschnerstr. 25 D-30167 Hannover mailto:reinhard.kotucha@web.de ---------------------------------------------------------------------------- Microsoft isn't the answer. Microsoft is the question, and the answer is NO. ----------------------------------------------------------------------------
Reinhard Kotucha wrote:
This seems to be wrong. select (1, ....) should only return the first argument, not both. I'm wondering why select (2, ....) works as expected. I must admit that I couldn't find any specs for select(), it just appears in some examples in the Lua book.
The reference manaul is separate. You can buy it on paper, but much easier is the free online version, because it conveniently starts with an index right after the toc: http://www.lua.org/manual/5.1/ From there: select (index, ยทยทยท) If index is a number, returns all arguments after argument number index. Otherwise, index must be the string "#", and select returns the total number of extra arguments it received. Best wishes, Taco
On 3 February 2010 Taco Hoekwater wrote:
Reinhard Kotucha wrote:
This seems to be wrong. select (1, ....) should only return the first argument, not both. I'm wondering why select (2, ....) works as expected. I must admit that I couldn't find any specs for select(), it just appears in some examples in the Lua book.
The reference manaul is separate. You can buy it on paper, but much easier is the free online version, because it conveniently starts with an index right after the toc:
Ahh, it's clear now. I overlooked it somehow there. Thanks, Reinhard -- ---------------------------------------------------------------------------- Reinhard Kotucha Phone: +49-511-3373112 Marschnerstr. 25 D-30167 Hannover mailto:reinhard.kotucha@web.de ---------------------------------------------------------------------------- Microsoft isn't the answer. Microsoft is the question, and the answer is NO. ----------------------------------------------------------------------------
participants (2)
-
Reinhard Kotucha
-
Taco Hoekwater