lua-users home
lua-l archive

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


On Wed, Sep 30, 2015 at 1:05 PM, Soni L. <fakedme@gmail.com> wrote:
>
>
> On 30/09/15 03:04 PM, Sean Conner wrote:
>>
>> It was thus said that the Great Soni L. once stated:
>>>
>>>
>>> On 30/09/15 01:34 PM, Luiz Henrique de Figueiredo wrote:
>>>>>
>>>>> If Lua doesn't need a registry then neither does C.
>>>>
>>>> That's not true. Lua is an embedded language and C code may need to
>>>> store things in a Lua state that Lua scripts cannot have access to
>>>> because of security. Not everything that can be done to Lua in C should
>>>> be exposed to Lua scripts.
>>>>
>>> function f()
>>> local i = 3
>>> return function() print(i) end
>>> end
>>>
>>> Does another script have access to i?
>>
>>    Only if the debug module is available.  But then again, if the debug
>> module is available, so is the registry.
>>
>>    -spc
>>
>>
> Precisely. The registry is useless.

Arguing that the registry is useless seems kind of useless. As
demonstrated, many (all?) users of the Lua C-API use it. They *don't*
use some other kind of alternative method. Therefore it's useful.

Is it redundant? Perhaps. Maybe they're redundant in the same way that
functions are redundant, in the face of goto.

I use it and its purpose is clear to me, both conceptually and actually.

I have yet to read about a problem that is being solved here...


-Andrew

--[[ extra

I had been in the habit of avoiding both the creation of tables and
table look ups, especially with string keys. I've mentioned before
that this habit never proved to be fruitful.

Looking at it another way: Imagine that you need to walk a tree
structure in your software. You want it to be fast, so you write it in
C. You quickly learn that the problem is hard, requiring you to manage
the collection of nodes, balance the tree (in some algorithms), etc.
You settle on a hash library to make it easier.  Let's say you pick
uthash.

The obvious question becomes: is uthash's implementation faster than
Lua's? Maybe, but they are not the same so the true answer is more
complex. Even if Lua is slower, it provides much more power. Does
uthash deal with garbage collection? How about self-referencing / week
values?

It might end up being the case that Lua is faster, once you add in
business logic and integration with the scripting language that you
need to support. Maybe only the tiniest chunks of C code are able to
provide benefit.

My semi-educated *assumption* is that Lua's hash table is amongst the
best implemented. It would help me to take this seriously if the claim
that it is slow was followed with a comparison to a specified chunk of
software.

--]]