# Getting the package options as a lua string, and allow arbitrary package options

I am making a lualatex-based class, which will be a thin wrapper around a lua library. I would like to use the luakeys package to process my options in lua, and would like to avoid declaring options. My question is two-fold:

1. Can I allow the package I'm writing to accept arbitrary options?
2. How would I retrive the options as a string in lua?

MWE:

\ProvidesPackage{MWE}

\RequirePackage{luacode}

\DeclareOption*{} % I think this is sufficient to allow arbitrary options..
\ProcessOptions\relax

\begin{luacode*}
texio.write_nl('VVVVVVVVVVVVVVVV')
texio.write_nl(token.get_macro('@nameuse{opt@MWE.sty}'))  -- isn't this
texio.write_nl(token.get_macro('@classoptionslist'))       -- isnt this

local luakeys = require('luakeys')
local kv = luakeys.parse(token.get_macro('???')) --is there a command, or way I can get the raw options
--  that were passed to this package as a str ?
texio.write_nl('VVVVVVVVVVVVVVVV')
luakeys.print(kv)
\end{luacode*}


The macro you want to access for the raw options is \@raw@opt@<file>.<ext>. And to prevent LaTeX from throwing errors on unknown options you should do \let\@unprocessedoptions\relax.

So this here is what you want:

\ProvidesPackage{MWE}

\RequirePackage{luacode}

\begin{luacode*}
local luakeys = require('luakeys')
local kv= luakeys.parse(token.get_macro('@raw@opt@MWE.sty'))
luakeys.print(kv)
\end{luacode*}
\AtEndOfPackage{\let\@unprocessedoptions\relax}% don't throw errors for option

\endinput


And using this driver file:

\RequirePackage[my=opt, opt=key]{MWE}
\stop


You'll get the following on the terminal output:

{
['opt'] = 'key',
['my'] = 'opt',
}


Caveat: Your options still need to survive one \edef assignment without breaking due to the way LaTeX handles options historically.