Re: ffi string definitions

  • From: Michal Kottman <k0mpjut0r@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Wed, 18 Jul 2012 11:23:58 +0200

On 18 July 2012 11:18, Patrick Masotta <masottaus@xxxxxxxxx> wrote:
> hi
>
> 1) I'm trying to pass a Regular Expresion from LUA to C on a string defined 
> with:
>
> ffi.new("char[?]", 0, "^[cC]:\\.*$");
> (forget about the length 0 on the definition)
>
> but LUA/FFI "interprets" the \\ finally adding a single \ to the string
> then I'm forced to pass "^[cC]:\\\\.*$" (Escaping LUA, then Escaping the 
> regex)
>
> is there anyway to force the no-interpretation of string content in the ffi 
> definition? i.e I can do that in BASH just using single quotes instead of 
> double quotes.

In Lua, you use the [[xxx]] form of string literal [1], so for your
example it will look like this: . To make sure you do not close the
literal using ]] in your regexp, you can write a number of equals
signs between brackets, like [==[^[cC]:\\.*$]==]

[1] http://www.lua.org/manual/5.1/manual.html#2.1

Other related posts: