lua-users home
lua-l archive

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


BOOLEAN TYPE

The 5.0 boolean type is really just an addon. Even in 5.0, any non-nil Lua
value _still_ works as 'true'. So the illusion of having a pure boolean type
is -well- an illusion. [If I'm wrong about this, someone please correct me!]

I've worked with both, but actually enjoy 4.0 for its simplicity. I do
'TRUE=1' and 'FALSE=nil' (which is basically unnecessary since any unnamed
var is a 'nil') to keep the coding look good. But it's ultimately your
choice.

The only place you'd really need booleans would be to index with them. You
cannot do 'tbl[nil]' but you can 'tbl[false]'. Don't know of cases where
this would be needed, though. :)


USERDATA/TABLES APPROACHES:

Userdata (alt1):
	+ faster (since calculation code etc. mainly in C)
	-/+ 'hidden implementation' from Lua
	+ ability to use true 'float's
	+ less memory-consuming

Tables (alt2):
	+ easy to code, all in Lua
	- slower
	- may cause memory consumption / cleanup issues

For the last point, to keep your embedded solution memory handling
predictable (as much as possible, anyways) I'd go Alt1. If that (or speed)
is not a reason, I'd go Alt2 (better for prototyping).

-ak


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


Hi there,

    Shortly after i had sent the message i was thinking about making the
base number type an integer, and just implementing the "decimal" values as a
user type, for the purposes of the system it will probably be some fixed
point type. i am not too sure about tables, i have not known of lua for that
long, but in time i guess i will learn more.

    i have been looking at both the 4.0.1 version and the 5.0 Beta, from
what i can see the 5.0 appears to be nicer. A few of the main points as for
why i might stick with 5.0 Beta is due to the addition of the boolean type,
and that the virtual machine is faster due to a register based design, over
the next few days i am sure i will come to a better understanding of lua and
what can be done. I will still keep the idea of 4.0.1 in the back of my
head, so if 5.0 is too much, then i will go to 4.0.1.

Cheers,

    Andrew Stanley Teirney

----- Original Message -----
From: "Asko Kauppi" <Asko.Kauppi@fi.flextronics.com>
To: "Multiple recipients of list" <lua-l@tecgraf.puc-rio.br>
Cc: <lua-l@tecgraf.puc-rio.br>
Sent: Thursday, February 06, 2003 2:11 AM
Subject: RE: Lua and adding types


>
> 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! ;)
###########################################
This message has been scanned by F-Secure Anti-Virus for Microsoft Exchange.