Skip to content

Override inherited LuaObject metamethods/members #118

Closed

Description

@URAKOLOUY5

I tried to implement this

LNode

[LuaObject]
public partial class LNode
{
    protected Godot.Node node;
    
    [LuaMetamethod(LuaObjectMetamethod.Call)]
    public static LNode New()
    {
        return new LNode
        {
            node = new Godot.Node()
        };
    }
    // other methods omitted (like queue_free, set_parent, get_parent, ...) 
}

LControl -> LNode

[LuaObject]
public partial class LControl : LNode
{
    [LuaMetamethod(LuaObjectMetamethod.Call)]
    public static LControl New()
    {
        return new LControl
        {
            node = new Godot.Control()
        };
    }
    // other methods (like get_position, set_position, modulate, ...)
}

So I can use exposed classes from Godot in Lua:

local control = Control()
local node = Node()

but it produces compile time error

LUACS007: Type 'LControl' already contains a 'Call' metamethod.

same with [LuaMember]

Activity

  1. URAKOLOUY5 commented on Apr 9, 2025

    @URAKOLOUY5
    Author

    I came to some solution (just marked method as new without attribute):

    public new static LNode New()
    {
        return new LControl
        {
            node = new Control()
        };
    }
    local control = Control()
    print(control:get_position())

    But I’m not sure if this is really a solution.
    it just worked

    I just need to get proof that this is intended
    (like for example __tostring works as is)

  2. akeit0 commented on Oct 10, 2026

    @akeit0
    Collaborator

    Fixed in #350. Derived Lua member names and metamethods now replace inherited bindings, while same-type duplicates retain their diagnostics. Verified with compilation tests, Lua execution tests, and CI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions