q66 / cffi-lua

A portable C FFI for Lua 5.1+
MIT License
176 stars 24 forks source link

__new metamethod never called #44

Closed jkl1337 closed 4 months ago

jkl1337 commented 6 months ago
local ffi = require("cffi")

local S = ffi.metatype("struct { int x; }", {
   __new = function(ct, x)
      error("__new Called")
      return ffi.new(ct, x or 0)
   end,
})

local s = S()

Expected is that this test case to raise an error if the library is to operate similar to LuaJIT and as described in semantics.md. However it returns without error.

This is the output on LuaJIT (with require("ffi"))

luajit: test.lua:5: __new called
stack traceback:
    [C]: in function 'error'
    test.lua:5: in function 'S'
    test.lua:10: in main chunk
    [C]: at 0x5facfc7a2cd0