lua-users home
lua-l archive

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


Hi,

First off: I only have a *little* experience with Lua.

Enough to integrate Lua into our app and (using tolua) provide a scripting
interface very quickly!:-)

Problem Background:
-------------------

Users can load scripts/execute them - and everything works fine.

The app is basically single-threaded and when Lua Scripts are executed they
just execute - do their thing - and return control back to the app when they
are done. In the meantime the scripts can call app functions (through
tolua). Typically nothing done via the script interface is going to take too
long.

Ok, the next thing i'd like to do is mimic the functionality of the existing
(in my app) plugin SDK. This allows users to build interactive "tools" which
act on the current dataset in memory.

The architecture of the tool (simplified) is this...

	o Tool registers itself with the app

	o the tool has functions like...

		+ init
		+ getData1( float )
		+ getData2( int )
		+ done

Now in the compiled tool - the app knows that a tool is "active" (has been
registered) and depending on internal events passes data to it via the
getData(...) functions.

Now to the Lua part :-)

My problem (as I see it) is this...

I can have a script that has something like..

-----------------------------
function init()
    ...
end

function getData1( val )
    ...
end
-----------------------------


I know how to execute the script - find a specific function & call it. This
allows me to load a script - run it & have the app call the lua script
function when appropriate (it does this by doFile(scriptfile),
lua_getglobal() lua_call() etc.)

let say the script is now...

-----------------------------
count = 0

function init()
    ...
end

function getData1( val )
    count = count + 1
end

function done()
    if count < 10 then
	print("count < 10\n" )
    end
    if count > 10 then
	print("count > 10\n" )
    end
end
-----------------------------

The problem is that the script might have a global variable (as in count
above). The app calls getdata1 & passes some data (we are ignoring it in
this example) to the script. At some point the app finds & calls the 'done'
script function - but count will always be zero (I think) because the script
is executed via a dofile call each time the app needs to get the appropriate
function.

I think the script needs to be running (or active at least) all the time -
probably in another thread? so that it can manage local memory, variables
etc based on the data which is passed to it by the app. How would I do this
(assuming its the correct approach). In that scenario, how does the app get
the function to call?

Anyway, i hope there is a simple existing lua solution....

help!:-)

Andy