lua-users home
lua-l archive

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


Lua itself (at least 5.0) allows the number type to be easily defined as
either double or long. For an embedded program, I would definately change
the native Lua type to integers. Makes the engine smaller & more efficient
for you.

To use floats for your own needs (not lua's) you could make them a userdata
type. This has some limitations, though, but consider it similar to wrapping
the complex numbers. This is alternative 1.

Alternative 2 would be to not use userdata but wrap the numbers as lua
tables instead. E.g. "nbr= { i=10, f=1234 }" or something the like. Again,
there is an analogy to complex numbers. 

For Alt2, you'll need to define a fixed resolution for the fractions. If
that cannot be done, use Alt1.

- ak

P.S. As a newcomer, I would rather recommend using Lua 4.0, instead of the
5.0 beta. If you don't need any of the new fancy features (e.g. better
multithreading support), 4.0 will do nicely for you. There is no 'forced
upgrade policy' within the Lua community! ;)


-----Original Message-----
From: Andrew Teirney [mailto:andrew@teirney.net]
Sent: 5. helmikuuta 2003 14:51
To: Multiple recipients of list
Subject: Lua and adding types


Hi there,

    I just happened to stumble across Lua while searching the internet for
something totally unrelated.

    None the less it appears as though Lua might be perfect for a particular
job that i am currently designing, except for one small part. That is the
intended environment for Lua is an embedded micro controller, a 16-bit micro
controller to be precise. The actual function of the Lua language is to
interface with native module and control the overall operation of a great
portion of work. It is done this was as runtime configuration for this type
of device is best described in some form of language.

    Anyway due to the micro-controller nature of the system using floating
point numbers for all number operations can be considered rather expensive
in time as opposed to using standard integers. I had thought about modifing
Lua to use just integers but the ability to use decimals will be required at
several points within the operation of the system.

    So in short, what i was wondering is whether anyone has any experience
or could point me in the best direction as to how to implement another base
type perhaps named integer whilst keeping the base type number of which will
most likely be used as a float type for storage size and speed.

Cheers,

    Andrew Stanley Teirney
###########################################
This message has been scanned by F-Secure Anti-Virus for Microsoft Exchange.