Re: Pass int64
Niki Bowe <[email protected]>
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
Theres a few ways you can check it. if you dont need to resolve overloads you can just check if its a udata and leave it at that. but if someone ever passes a different udata type (say another luabind object) then itll crash without much helpful information. To be safer Id say to stash my metatable in the registry under a known fixed key and compare it against that. I tried registering __int64 as a luabind::class_ and it didnt work. but the alternative (and probably what Id do If we did this again) would be to make a light wrapper class and use that. Its easier to work with than the converter method. eg if you have register a function that takes __int64 params or returns them then you need to have your converter #included or you get the "tried to use an unregistered type" error at runtime. Valery wrote: > Hello, > > 2 Daniel Wallin: > Thanks for your sample. I am using LUA with 32 bit integers. Using > your version of default_converter<int64>, I may read values as int64 > in my cpp functions. Yes, this sample does not fully support __int64, > but the sample is really useful for me. > > 2 Niki Bowe: > Thanks for your sample. This seems fully support __int64. I merged it > with Daniel's sample (I use new luabind version) and the result worked > for me. > But how to check that metatable is correct? I know this does not > relates to luabind, but could you please provide a sample? > > Thanks, > Valery. > > ----- Original Message ----- > *From:* Niki Bowe <mailto:[email protected]> > *To:* [email protected] > <mailto:[email protected]> > *Sent:* Monday, June 01, 2009 5:33 AM > *Subject:* Re: [luabind] Pass int64 > > > James Porter wrote: >> Niki Bowe wrte: >> >>> Done correctly that is the best solution. Itll allow you to do >>> arithmetic on 64 bit integers in lua. >>> Though there is a bit more to it than that. >>> lua_Number will need to be able to hold int64 values without loss. >>> which means youll need to either go with int64 as lua_Number (ie integer >>> only lua) >>> or long double as lua_Number (non portable. no guarantee it can >>> represent all 64 bit ints. >>> >> >> Are you sure about this? Because that would imply that Lua 5.1 doesn't >> work properly when compiled for a 64-bit platform since, by default, >> LUA_INTEGER is #defined to ptrdiff_t. That seems like something the Lua >> developers would have considered, but maybe not... >> >> - Jim >> > Lua certainly works on 64 bit platforms. > It just doesnt do what you might expect. depending on what you expect. > > The problem here is that lua_Number (by default) is set to double. > and internally lua values are represented by the following union > /* > ** Union of all Lua values > */ > typedef union { > GCObject *gc; > void *p; > lua_Number n; > int b; > } Value; > > Internally when you push an integer it casts it to lua_Number. (see > the code for lua_pushinteger). > So if you want to be able to represent any 64 bit integer in lua you > will have to do one of the things I suggested in a previous email. > > ------------------------------------------------------------------------ > ------------------------------------------------------------------------------ > Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT > is a gathering of tech-side developers & brand creativity > professionals. Meet > the minds behind Google Creative Lab, Visual Complexity, Processing, & > iPhoneDevCamp as they present alongside digital heavyweights like > Barbarian > Group, R/GA, & Big Spaceship. http://p.sf.net/sfu/creativitycat-com > > ------------------------------------------------------------------------ > _______________________________________________ > luabind-user mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/luabind-user > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------------ > OpenSolaris 2009.06 is a cutting edge operating system for enterprises > looking to deploy the next generation of Solaris that includes the latest > innovations from Sun and the OpenSource community. Download a copy and > enjoy capabilities such as Networking, Storage and Virtualization. > Go to: http://p.sf.net/sfu/opensolaris-get > ------------------------------------------------------------------------ > > _______________________________________________ > luabind-user mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/luabind-user > ------------------------------------------------------------------------------ OpenSolaris 2009.06 is a cutting edge operating system for enterprises looking to deploy the next generation of Solaris that includes the latest innovations from Sun and the OpenSource community. Download a copy and enjoy capabilities such as Networking, Storage and Virtualization. Go to: http://p.sf.net/sfu/opensolaris-get _______________________________________________ luabind-user mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/luabind-user