Use of function references rather than function names to store button
actions. This allows using all kinds of functions, including non global
ones. Note that the old mechanism using global function names is not
supported anymore. Existing scripts will need to be fixed (-> just
remove the quotes around the function name).
if( !p_ext->p_sys->L )
return VLC_SUCCESS;
if( !p_ext->p_sys->L )
return VLC_SUCCESS;
- return lua_ExecuteFunction( p_mgr, p_ext, (const char*) p_widget->p_sys, LUA_END );
+ lua_State *L = GetLuaState( p_mgr, p_ext );
+ lua_pushlightuserdata( L, p_widget );
+ lua_gettable( L, LUA_REGISTRYINDEX );
+ return lua_ExecuteFunction( p_mgr, p_ext, NULL, LUA_END );
/**
* Execute a function in a Lua script
/**
* Execute a function in a Lua script
+ * @param psz_function Name of global function to execute. If NULL, assume
+ * that the function object is already on top of the
+ * stack.
* @return < 0 in case of failure, >= 0 in case of success
* @note It's better to call this function from a dedicated thread
* (see extension_thread.c)
* @return < 0 in case of failure, >= 0 in case of success
* @note It's better to call this function from a dedicated thread
* (see extension_thread.c)
assert( p_ext != NULL );
lua_State *L = GetLuaState( p_mgr, p_ext );
assert( p_ext != NULL );
lua_State *L = GetLuaState( p_mgr, p_ext );
- lua_getglobal( L, psz_function );
+ if( psz_function )
+ lua_getglobal( L, psz_function );
if( !lua_isfunction( L, -1 ) )
{
if( !lua_isfunction( L, -1 ) )
{
static int vlclua_dialog_add_button( lua_State *L )
{
/* Verify arguments */
static int vlclua_dialog_add_button( lua_State *L )
{
/* Verify arguments */
- if( !lua_isstring( L, 2 ) || !lua_isstring( L, 3 ) )
+ if( !lua_isstring( L, 2 ) || !lua_isfunction( L, 3 ) )
return luaL_error( L, "dialog:add_button usage: (text, func)" );
extension_widget_t *p_widget = calloc( 1, sizeof( extension_widget_t ) );
p_widget->type = EXTENSION_WIDGET_BUTTON;
p_widget->psz_text = strdup( luaL_checkstring( L, 2 ) );
return luaL_error( L, "dialog:add_button usage: (text, func)" );
extension_widget_t *p_widget = calloc( 1, sizeof( extension_widget_t ) );
p_widget->type = EXTENSION_WIDGET_BUTTON;
p_widget->psz_text = strdup( luaL_checkstring( L, 2 ) );
- p_widget->p_sys = strdup( luaL_checkstring( L, 3 ) );
+ lua_settop( L, 3 );
+ lua_pushlightuserdata( L, p_widget );
+ lua_insert( L, 3 );
+ lua_settable( L, LUA_REGISTRYINDEX );
+ p_widget->p_sys = NULL;
return vlclua_create_widget_inner( L, 2, p_widget );
}
return vlclua_create_widget_inner( L, 2, p_widget );
}
/* Delete widget */
*pp_widget = NULL;
/* Delete widget */
*pp_widget = NULL;
+ if( p_widget->type == EXTENSION_WIDGET_BUTTON )
+ {
+ /* Remove button action from registry */
+ lua_pushlightuserdata( L, p_widget );
+ lua_pushnil( L );
+ lua_settable( L, LUA_REGISTRYINDEX );
+ }
vlc_object_t *p_mgr = vlclua_get_this( L );
vlc_object_t *p_mgr = vlclua_get_this( L );
- row_span, col_span represent the relative size of a widget on the grid. A widget with col_span = 4 will be displayed as wide as 4 widgets of col_span = 1.
Example: w = d:add_label( "My Label", 2, 3, 4, 5 ) will create a label at row 3, col 2, with a relative width of 4, height of 5.
- row_span, col_span represent the relative size of a widget on the grid. A widget with col_span = 4 will be displayed as wide as 4 widgets of col_span = 1.
Example: w = d:add_label( "My Label", 2, 3, 4, 5 ) will create a label at row 3, col 2, with a relative width of 4, height of 5.
-d:add_button( text, func, ... ): Create a button with caption "text" (string). When clicked, call function "func". func is a string.
+d:add_button( text, func, ... ): Create a button with caption "text" (string). When clicked, call function "func". func is a function reference.
d:add_label( text, ... ): Create a text label with caption "text" (string).
d:add_html( text, ... ): Create a rich text label with caption "text" (string), that supports basic HTML formatting (such as <i> or <h1> for instance).
d:add_text_input( text, ... ): Create an editable text field, in order to read user input.
d:add_label( text, ... ): Create a text label with caption "text" (string).
d:add_html( text, ... ): Create a rich text label with caption "text" (string), that supports basic HTML formatting (such as <i> or <h1> for instance).
d:add_text_input( text, ... ): Create an editable text field, in order to read user input.
dlg:add_label("<b>Movie Title</b>", 1, 2, 1, 1)
local item = vlc.input.item()
txt = dlg:add_text_input(item and item:name() or "", 2, 2, 1, 1)
dlg:add_label("<b>Movie Title</b>", 1, 2, 1, 1)
local item = vlc.input.item()
txt = dlg:add_text_input(item and item:name() or "", 2, 2, 1, 1)
- dlg:add_button("Okay", "click_okay", 3, 2, 1, 1)
- dlg:add_button("*", "update_title", 4, 2, 1, 1)
+ dlg:add_button("Okay", click_okay, 3, 2, 1, 1)
+ dlg:add_button("*", update_title, 4, 2, 1, 1)
dlg:show() -- Show, if not already visible
end
dlg:show() -- Show, if not already visible
end
if not list then
list = dlg:add_list(1, 3, 4, 1)
if not list then
list = dlg:add_list(1, 3, 4, 1)
- button_open = dlg:add_button("Open", "click_open", 1, 4, 4, 1)
+ button_open = dlg:add_button("Open", click_open, 1, 4, 4, 1)
end
-- Clear previous results
end
-- Clear previous results