Re: Confirming silliness

  • From: Mike Pall <mike-1503@xxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Tue, 10 Mar 2015 08:09:00 +0100

William Adams wrote:
> passing in the strings directly didn't seem to work in practice.
> I don't think it can  because the ffi needs to know what to cast
> it to (variable arguments), and it doesn't know that from the
> function signature. It could assume 'const char *', but that may
> or may not be correct, and thus I explicitly cast.

No, this works fine. The rules are explicitly stated here:

  http://luajit.org/ext_ffi_semantics.html#convert_vararg

> and thus I explicitly cast.                                     

Sadly so. First, this creates dangling references, which is a bad
thing to do. Lua strings are a perfectly fine way to store the
content of, err, strings.

Second, you could do the cast just before use to avoid the
dangling reference. But, anyway, the cast is unnecessary.

--Mike

Other related posts: