lua-users home
lua-l archive

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


On Thursday, January 31, 2008 Al Pfalzgraf wrote: 

> I am applying Lua to a DeviceNet protocol project.  DeviceNet has a
> very large set of data types including some 64 bit types.  Within C
> code they can be declared using __int64 or unsigned __int64.
>  
> lua_pushnumber results in warnings or errors with these.
> warning C4244: 'function' :conversion from '__int64 ' to 'double ', possible loss of data
> warning C4244: 'function' : conversion from 'unsigned __int64 ' to 'double ', possible loss of data
> error C2520: conversion from unsigned __int64 to double not implemented, use signed __int64
>  
> Is there an extension library that addresses this, or am I about to create one?

You can do it without an extension by abusing the string type: since
strings are really just blobs of bits, you can make 8 byte binary
strings for your large numbers, e.g., with lua_pushlstring(), and get
them back with lua_tolstring().

If you find this distasteful :-) ... you can still get by without an
extension by storing the large numbers as a table or tuple (search
http://lua-users.org/wiki/FindPage for "tuple").

A pure Lua approach using tables:
http://oss.digirati.com.br/luabignum/index.htm

There are other add-on approaches...

Lnum, http://luaforge.net/projects/lnum/ modifies the Lua core to have
large numbers.

And libraries...

Bignum, http://luaforge.net/projects/bignum/ adds support for "big
integers based in the BIGNUM of the OpenSSL C package."

LGMP, http://members.chello.nl/~w.couwenberg/lgmp.htm is a available.

There is also a Lua binding for MAPM
http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/lmapm.tar.gz

e

-- 
Doug Currie
Londonderry, NH, USA