lua-users home
lua-l archive

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


Hi there,

    I have been mulling over whether i should post this message, anyway i
have decided to.

    What i am wanting to know is what is the best way to do what i am about
to describe. Please forgive me if what i write is rather cryptic, i am not
the best as putting my ideas into words.

    The system i am playing around with has many devices attached to it, let
say for example sake a keyboard, a mouse and a magcard reader. I want to be
able to have a handler script for each of these devices running at the same
time, naturally this is not possible without multi processors, but what i am
meaning is using system threads to make each script appears as though it is
executing continuously. I have thought about the possibility of using
lua_newthread and so forth and putting in locking mechanisms, but i am not
too familiar with when the locking mechanisms are called, i have had a quick
look and lock and unlock appear to be called quite a bit, in my case i don't
want other lua instances to be locked from executing except when accessing
shared data space.

    As each device is to be treated independant of one another i am thinking
i might need to call lua_open for each device? The stumbling block i have is
the communication between the scripts, this will essentially be data. What i
am planning on doing is adding a userdata type to the global environment of
each lua state created through lua_open and then associating a metatable
with this user data which handles the __index and __newindex metamethods.
All calls to the __index and __newindex metamethod could be made atomic so
as one instance cannot be writing whilst another is partway through
attempting a read but was switched out. What i am not sure about is whether
what i am planning on doing is feasible, or whether the lua_newthread method
already supports what i am wanting to do, essentially i just want to lock on
accessing a certain table in the global environment or what have you.

    With regards to the best method of implementing this global registry
(assuming this is the best method) i was thinking of using another lua_open
instance for the storage of the data, i would naturally only store number,
string, booleans, and tables, no functions or userdata. Any other ideas?

Cheers,

    Andrew Stanley Teirney