tarantool / tarantool/tarantool

lua: add luaL_getmetatype() for cdata

Open
#3,915 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature lua
Dominant language
Lua
Stars
3.7k
Forks
419
Avg merge
1d 23h
Merged PRs (30d)
88

Description

I have added luaL_iscallable() with cdata support in the scope of #3276 (it didn't land into 1.10/2.1 for now) and found that ability to get metatype of a cdata object (something like getmetatable() for tables) sometimes useful.

I think we need to provide it and export for C modules and ffi. The name can be discussed, but I propose luaL_getmetatype().

It also will help with 2nd point of https://github.com/tarantool/tarantool/issues/1517#issuecomment-240405735

Side note: it also seems that it worth to add something like ffi.metatype() to C API to set metatypes.

Known workaround: https://github.com/corsix/ffi-reflect/blob/4ee6eb7bd7e51312ec6e2d84c1d650a7efa2a895/reflect.lua#L357

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the existing luaL_iscallable() cdata work from #3276 and the ffi-reflect workaround linked in the issue. Clarify the API name and scope with maintainers, including whether setting metatypes belongs in this change. Done means an agreed, exported way to retrieve cdata metatypes for C modules and FFI, with coverage for the intended cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.