lua-users home
lua-l archive

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


Thanks a lot for your answers.

I want to make it a little bit more clearer.
I don't have to worry about concurrency access. Both interpreter are
called within a single thread alternately.

Each interpreter executes the same function (provided by the user).
(The background: Lua is used in a protocol analyzer and the first
interpreter handles the incoming, the second the outgoing data.)

The C++ program passes a received data byte of the incoming channel to
the first interpreter and executes the given function. A byte received
on the outgoing channel is passed to the second interpreter.
The result of the execution is returned to the C++ caller function and
the whole process is strongly sequently.

So I would not like to add a thread module (or another module) to our
integrated Lua interpreter.

I'm rather looking for a plain solution. I already wrote a module for
sharing global data between both interpreters, but the handling in the
Lua script is a little bit annoying. At the moment the user has to write
something like this:

gv.set("MyGlobalBool",true)

if gv.get("MyGlobalBool") then ... end

(gv means global vars). The module handles boolean, numbers and strings.
With it the user can - for instance - set a flag when the incoming data
matches a certain sequence and uses the flag in the handling of the
outgoing data.

But I would like to prefer:

gv["MyGlobalBool"] = true
if gv["bwrite"] then ... end

I know, that I can create a Lua table in C++ (or of course C) and using
the metatable to overwrite/define my own set/get functions. And I guess
that I could pass such a table via userdate to both interpreter.

I'm just unsure if this approach leads in the right direction.

Best regards

Joachim