Re: Lua syntax ambiguity

Sean Conner <[email protected]>
Newsgroups gmane.comp.lang.lua.general
Message-ID <[email protected]>
It was thus said that the Great 'Martin Eden' via lua-l once stated:
> Hi Sean,
> 
> On 2026-08-18 20:36, Sean Conner wrote:
> >   What are you doing that requires this level of detail?
> Just printing tables.

  Okay.  I have a similar function.  Two actually, one to dump to a string
(which has been occasionally useful) and a second one that dumps to stdout.

> >   That aside, it sounds like you have some form of AST that you want to 
> >   turn
> >into textual Lua (possibly with a minimum of extra space for some reason).
> >Per your example:
> >
> >	t={['a']=1}
> >
> >   At some point you have a string.  By what criteria are you using to 
> >   write
> >a string as [[...]]?  Why not "..."?  Or '...'?  Avoid the issue entirely.

> Objective is not "avoid issue and make job done". Objective is
> "deal with it. Preferably nicely".

  I mean, how does your code determine which quoting method to use?  In mine
[1], I just use double quotes, and will escape control codes or byte values
larger than 126.  For example:

> dump("x",x)
x =
{
  bar = C_FUNCTION,
  file = file (0xcbc720),
  [true] = false,
  ["one\ntwo"] = 12.000000,
  foo = "1\n2\t3\v4\a5\000\001\002b\226\141\133",
  ["[[a]]"] = 2.000000,
  x = x,
}

  I sidestepped the issue of using [[...]] and '...' by not using them [2].

  -spc

[1]	https://github.com/spc476/lua-conmanorg/blob/fa5bcdbdcc0ceeeadd238a470c063f8b843c11cd/lua/table.lua#L78

[2]	Yes, some values are not valid Lua (like "bar = C_FUNCTION") but
	some Lua values are not easy to deal with (userdata, functions and
	threads come to mind).  I was able to solve this somewhat with my
	CBOR [3] implemetation, but never published it.  Also, this means
	that some tables can't be properly round-tripped with my code; that
	doesn't bother me too much and hasn't been an issue.

[3]	Concise Binary Object Representation:

		defined: <https://cbor.io/>
		my module: https://github.com/spc476/CBOR

-- 
You received this message because you are subscribed to the Google Groups "lua-l" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/lua-l/20260818204706.GD13121%40brevard.conman.org.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.