Wouldn't it be easiest just to define it with \newskip to get the tex input syntax and then access that skip register from lua?
David On Sat, 26 Jan 2019 at 05:59, Henri Menke <[email protected]> wrote: > > Dear list, > > I am trying to define a command which behaves like an internal register > using the `token` library. However, there are some complications. For > example a register has to be settable using both > > \register=<number> > \register<number> > > Additionally, if no number is given it should raise a “cannot be used in > vmode” error or similar. Also it has to be possible to get the value > using `\the`. Below you can find a minimal example where I have already > achieved some of these things but others fail miserably. > > Cheers, Henri > > P.S.: I have also attached a much more complex example, so you can see > that I actually want to emulate pdfTeX's \pdfadjustinterwordglue. > > --- > > \directlua{ > local value = 0 > % > function register() > local str = token.scan_string() > % > if str then > local int = string.gsub(str,"=","") > value = tonumber(int) > else > tex.sprint([[\numexpr]] .. value .. [[\relax]]) > end > end > } > > \protected\def\register{\directlua{register()}} > > \register=1 > \register=12 > \register=123 > > \register1 > \register12 > \register123 > > \the\register > \the\register > \the\register > > \bye
