lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Does anyone have a cunning piece of pure-Lua code for argifying a
string? That is, turning this:

	foo bar "baz bloo \"fnord" wibble

into this:

	{'foo', 'bar', 'baz bloo "fnord', 'wibble'}

...?

I've had a look at the wiki, as this is a fairly stock problem, but
don't see anything.

Not at all pure Lua, but the Apache Portable Runtime contains apr_tokenize_to_argv() which does this and my Lua/APR binding includes support for this function:

http://peterodding.com/code/lua/apr/docs/#apr.tokenize_to_argv

You might not like the large dependency [or the binary module factor] but at least it exists! Worst case you could translate the APR command line parser to Lua ;-)

 - Peter Odding