lua-users home
lua-l archive

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

You can always test your lpeg _expression_ to make sure it works, then store it as a chunk (string). Whenever you wanted to use it in lpeg, you'd use loadstring or one of its family. You could even build such strings at runtime and then compile them. Not the cleanest solution, but it would work.

On Sat, May 23, 2015 at 7:50 AM, Dirk Laurie <> wrote:
2015-05-23 14:28 GMT+02:00 Александр Машин <>:

> is it possible to save a compiled LPeg grammar or pattern to file or
> database and then to load it thence by means of pure Lua?


> Effectively it means whether I can cast userdata to string and string to
> userdata correctly.

A userdata is a black box of memory that can only be accessed by
C routines. Even if you cast its memory block to a C string and push
that C string onto the stack as a return value, the Lua string will refer
to a newly created copy owned by Lua, not to the original string pointer.

Brigham Toskin