lua-users home
lua-l archive

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

Hi, Dan

very easy: just export a function that creates an instance of your class

function myclass()
    local c = {}
    c.myfunc = function ()
        --do stuff
    c.n = 10
    return c


sincerely yours,

----- Original Message ----- 
From: "Dan East" <>
Subject: Type definition within LUA

>   Hi.  I wish to allow the user to define classes within LUA that can be
> instantiated from the host app (written in C of course).
> Something along this line:
> myclass={}
> function myclass:myfunc()
>   --do stuff
> end
> myclass.n=10
> host.RegisterClass(myclass)
>   The host application can then create as many instances of that object as
> desired within the LUA environment, where each instance's data will be
> unique.
>   I am currently using lunar to interface my C++ classes with good
> but I need to allow class-like definitions within LUA as well.
>   Thanks.
>   Dan East