lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi,

can eventually someone point me to a short example for how to use __index and __newIndex (eventually in context Lunar) to access C++ methods like properties?

Example:

class A
{
public:
    static const char className[];
    static Lunar< A >::RegType methods[];
public:
    void SetValue( int v );
    int GetValue() { return m_v; }
private:
    int m_v;
}

const char A::className[] = "A";

Lunar< A >::RegType A::methods[] = {
    method( A, SetValue ),
    method( A, GetValue ),
    { 0, 0 }
};

default use in Lua:

a = A:new()
a:SetValue( 1 )
print( a:GetValue() )

expected use:

a = A:new()
a.value = 1
print( a.value )


Best Regards
Micha