lua-users home
lua-l archive

Re: Type definition within LUA

[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
 end
 c.n = 10
 return c
end
host.RegisterClass(myclass)
sincerely yours,
Grisha
----- Original Message ----- 
From: "Dan East" <dan@naxs.com>
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
success,
> but I need to allow class-like definitions within LUA as well.
> Thanks.
>
> Dan East
>

AltStyle によって変換されたページ (->オリジナル) /