[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Exposure of nil to end-users
- From: steve donovan <steve.j.donovan@...>
- Date: Thu, 5 Feb 2009 12:44:56 +0200
On a another note, it would be cool if there were __tostring and
__tonumber metamethods. Then defining such a NULL proxy object is
really easy. It still retains its identity as NULL (i.e. it isn't
really 0 or "") but can have safe default behaviour.
These would be similar to the overridable conversion operators of C++.
steve d.
On Thu, Feb 5, 2009 at 12:34 PM, Ben Harper <rogojin@gmail.com> wrote:
> Hmm thanks guys..
>
> The idea of making a special 'NULL' type sounds best - think I'll go with that.
>
>
> On Thu, Feb 5, 2009 at 12:30 PM, steve donovan
> <steve.j.donovan@gmail.com> wrote:
>> This is the famous 'nullable type' problem.
>>
>> One option is for the database layer never to return nil in the case
>> of a NULL field, but "" or 0 depending on the type of the field.
>>
>> Another option is to make a special Null object which has default
>> string-like and number-like semantics. But this is tricky to do
>> properly, since you'd need to define methods like 'null:sub(1,1)' etc
>> as well as override __concat, __add, etc.
>>
>> steve d.
>>
>> On Thu, Feb 5, 2009 at 12:05 PM, Ben Harper <rogojin@gmail.com> wrote:
>>> I am using Lua as a language that allows end-users to manipulate
>>> database records.
>>> My problem is that I'm not sure how to expose NULL values to the user.
>>>
>>> In this example, value = nil
>>> User Types: value .. "abc"
>>> User Expects: 'abc'
>>> User Gets: Error: attempt to concatenate a nil value
>>>
>>> Has anybody had a similar problem, and how have you dealt with it?
>>>
>>> Thanks,
>>> Ben
>>>
>>
>