Cool VL Viewer forum

View unanswered posts | View active topics It is currently 2025-08-09 15:44:46



Reply to topic  [ 12 posts ]  Go to page Previous  1, 2
Help with a defining a Lua function utilising a callback 
Author Message

Joined: 2009-03-17 18:42:51
Posts: 6030
Reply with quote
I really don't understand why you find it hard to understand... It's all explained in the documentation...

g0rd0ngrfr33mailgr wrote:
I'm not sure I understand the distinction between the two callbacks.
OnLuaFloaterOpen() is only called for a Lua floater, when you open it. This callback is used to setup Lua UI elements callbacks, or do things you want only to do once for the lifetime of the Lua floater.
OnLuaFloaterAction() is called each time the user performs an action on an UI element (which names follows the naming convention for each type, such as "buttonN" for buttons) of a Lua floater: it is for doing exactly what you want to do here, i.e. react to a click on a button to trigger a custom Lua function/piece of code.

g0rd0ngrfr33mailgr wrote:
I also don't understand why Action is executed within the context and Open is not.
They are BOTH executed in the same "context" (or rather in the same "Lua state", i.e. the same Lua script instance), the one of the automation script.

However, the Lua commands you set on UI elements (either via SetLuaFloaterCommand() from the automation script and usually inside a OnLuaFloaterOpen() callback, or from a lua_command="SomeLuaScriptLine" in the UI element XUI definition) are executed in a temporary/transitory Lua state different from the automation script, so you cannot directly call functions defined in the latter from these commands.


2025-05-09 13:35:09
Profile WWW

Joined: 2011-09-27 11:18:31
Posts: 244
Reply with quote
Thank you for your explanation. I suppose I lack the experience. I'll keep this rule of thumb:
- OnLuaFloaterOpen(): used for SetLuaFloaterCommand(), provided all called functions are built-in.
- OnLuaFloaterAction(): otherwise, with possible use of OnAutomationMessage().


2025-05-09 14:27:45
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 12 posts ]  Go to page Previous  1, 2

Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software.