Calling Lua Functions

Sorry if this question seems simple, but I am brand new to Vera and Lua.

Does anyone know where to place functions so that they can be called?

I have tried to create a function by placing the function in a scene, but I have had only partial success.

Say that Scene A has the following:

function F00()
sState=“Away”
end

And Scene B has the following:

F00()

This code works great as long as Scene A is called before Scene B (since the last Vera reboot), and the global variable “sState” will be loaded as expected.

However, if Scene B is called without Scene A having been called first (since the last Vera reboot), the code will fail with the message “Address of F00 is nil”. It appears that the Lua engine needs to “see the function” prior to envoking it.

I tried putting the function declaration in the Lua startup script, but that does not work either. It appears that the startup script runs in a separate run time environment from the scene environment, so F00 is still not recognized (the same effect seems to happen with global variables declared in the startup script).

In an attempt to be clever, I put a lua.call_action in the startup script to run an “Initialize” scene. Still did not work, as the scene does not get run. I suspect that the different run time environment is also preventing the called scene from executing.

I am running 1.0.979.

Has anyone got this to work?

Hm, I have the same problem. I discovered tolua thanks to the scriptingmod. Its great, I can even use my own homebrewn string class inside Lua now

But, I have one problem. I was using LuaPlus as well, it makes it a lot easier to go through tables and call Lua functions from C. Unfortunatly, it refuses to work now. It does work again when I remove the .lib file from the list named lua_tolua.lib. or something similar. Right now Im trying to find a GCC compiler to compile tolua standalone. Maybe it works better. After spending a day on this, I feel like its fighting a losing battle.

And I have no idea why. Both LuaPlus and ToLua are compiled, yet they give problems. The lua function redefinitions are logical though. And I hope that I can get rid of those by compiling tolua separate if I can get it compile at all.

Maybe someone else has an interesting suggestion how to get ToLua to work, while also using LuaPlus? Then its really the best of both worlds .

lindquist: Does it have any advantages to use a DLL, could it save my problems maybe?

Its hard to explain what the problem exactly is. Sometimes I get strange source code errors as well, although it seems not to do that anymore - but LuaPlus is still doing 100 nothing. Or the otherway around. I just got all kind of assertions… Real unfortunate, cause combined it would be awesome. Easy calling of Lua functions from C, and all your classes or certain ones exposed for Lua.

Right now I got it kinda working… I can call a function from C in Lua, using luaPlus… but the Post call which the LuaPlus makes gives a big error. Somehow because of a source file confusing I guess… strange stuff

Enough rambling…