[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Help: Has someone knows how to replace lua_Number with a C++ class?
- From: Thomas Jericke <tjericke@...>
- Date: Tue, 22 May 2012 11:06:18 +0200
Xavier Wang wrote on 2012-05-21/14:24:
the issue is not at memory garbage: using C++ class means you can
using C++ operations, such as operator= or copy constructor. the issue
is this class is in a union: that means C++ don't know call which copy
constructor if you call setobj :-( so maybe I need make a function
version of setobj and something others. regards, Xavier Wang.
I also have a version of my interpreter with a C++ class as lua_number.
What I had to do - and what I suggest to you too - is to have a base
class of the C++ class you are using that has only the default
constructer. This is the limitation that you have if you want to use a
object of type class in a c++ union.
In my case I had a class fixed64 with fixed point operations and
constructors from different types (int, double...) what I had to do is
to create a class fixed64base, then I moved all operatiors and methods
to fixed64base except any contructors.
You will still need to do some adaptions to the interpreter after that,
but the compiler errors will lead you through those changes.