Run my lua code during initialization/reset?

I have some functions and variables that are currently in an “initialization” scene that I want code in other scenes to be able to use - but the “initialization” scene needs to run first to globalize the functions and variables before the other scene functions can “see” it.

How do I get that initialization code to run whenever the lua engine starts up?

Either I need a way to make the current scene run automatically on startup or I place the code somewhere else?

Thanks,
Neilios

Neillos,
I was going to recommend that you try editing the Startup Lua under Luup PluginsEdit Startup Lua, but then I tried a snippet of code myself in 1.0.862:

[tt] luup.log(“Starting custom startup LUA”)
[/tt]

and checked the logs after Save and also after rebooting Vera to get the whole startup sequence. In both cases, there was no output in [tt]/var/log/cmh/LuaUPnP.log[/tt] so either:

a) Startup Lua codeblocks never fire OR;
b) [tt]luup.log(…)[/tt] doesn’t work during startup blocks

at any rate, once it can be verified, this seems like the logical “trigger” spot to put the type of code you’re writing.

There are other options, like Lua modules, but they’re increasing the level of complexity for what you’re doing. I’d like to see the simple ones work first.

MCV: Does the Startup Lua block work under Luup PluginsEdit Startup Lua?

Startup Lua should work. Let me test it tomorrow and post here.

I’ve just tried the same thing and got no log message. The actual startup code itself was loaded as is shown in the log file:

08 08/20/09 18:34:05.126 JobHandler_LuaUPnP::HandleActionRequest argument inUserData={ "StartupCode": "luup.log(\"START\")" } <0x340e>

… but there was just no display of the log text in my call.

Neilios

@micasaverde,

Did you get to try the luup startup code - any issues found or a workaround/alternative?

Thanks,
Neilios

I’ve just worked around this by creating a plugin and putting all my functions in there and calling the initialization code in its startup.

I have a different issue now with the UI customization:
http://forum.micasaverde.com/index.php?topic=1784.0

Neilios

neilios-

Can you give me some details on how you created a plugin where the functions could be accessed directly?

Thanks in advance!!

How does one do this in UI 7? I can’t find any Startup LUA to edit.

– Geoff

In APPS → Develop Apps → Startup LUA

You can also put Startup LUA code in PLEG and it will run as part of that plugins startup.

I have found that some things do not work when run in the LUA startup code, most likely because the startup code is executed before the environment has been fully brought up.

I solved this by creating a scene (I called “Initialize”), that gets called as the last thing the start up code does. The Initialize scene will not actually run until the environment is ready to go, so things that require that environment can safely run from within that scene.

I did this because I wanted to lock my doors when Vera restarts, but the locking would not work when executed in the Startup code.

In startup … do a luup.call_delay and run your code 30 seconds later.