src/lua_interface.c File Reference

#include "textadept.h"

Defines

#define streq(s1, s2)   strcmp(s1, s2) == 0
#define l_insert(l, i)   lua_insert(l, (i < 0) ? lua_gettop(l) + i : i)
#define l_append(l, i)   lua_rawseti(l, i, lua_objlen(l, i) + 1)
#define l_cfunc(l, f, k)
#define l_archive(l, k)
#define l_togtkwidget(l, i)   (GtkWidget *)lua_touserdata(l, i)
#define l_mt(l, k, i, ni)
#define l_pushscninteger(i, n)
#define toggled(w)   gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))
#define toggle(w, b)   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), b)
#define child1(p)   gtk_paned_get_child1(GTK_PANED(p))
#define child2(p)   gtk_paned_get_child2(GTK_PANED(p))
#define editor_dpi(editor)   l_get_docpointer_index(SS(editor, SCI_GETDOCPOINTER, 0, 0))

Functions

static void clear_table (lua_State *lua, int index)
static void warn (const char *s)
static int l_buffer_mt_index (lua_State *)
static int l_buffer_mt_newindex (lua_State *)
static int l_bufferp_mt_index (lua_State *)
static int l_bufferp_mt_newindex (lua_State *)
static int l_view_mt_index (lua_State *)
static int l_view_mt_newindex (lua_State *)
static int l_ta_mt_index (lua_State *)
static int l_ta_mt_newindex (lua_State *)
static int l_pm_mt_index (lua_State *)
static int l_pm_mt_newindex (lua_State *)
static int l_find_mt_index (lua_State *)
static int l_find_mt_newindex (lua_State *)
static int l_ce_mt_index (lua_State *)
static int l_ce_mt_newindex (lua_State *)
static int l_cf_buffer_delete (lua_State *)
static int l_cf_buffer_text_range (lua_State *)
static int l_cf_view_focus (lua_State *)
static int l_cf_view_split (lua_State *)
static int l_cf_view_unsplit (lua_State *)
static int l_cf_ta_buffer_new (lua_State *)
static int l_cf_ta_dialog (lua_State *)
static int l_cf_ta_get_split_table (lua_State *)
static int l_cf_ta_goto_window (lua_State *)
static int l_cf_view_goto_buffer (lua_State *)
static int l_cf_ta_gtkmenu (lua_State *)
static int l_cf_ta_iconv (lua_State *)
static int l_cf_ta_reset (lua_State *)
static int l_cf_ta_quit (lua_State *)
static int l_cf_pm_activate (lua_State *)
static int l_cf_pm_add_browser (lua_State *)
static int l_cf_pm_clear (lua_State *)
static int l_cf_pm_fill (lua_State *)
static int l_cf_pm_focus (lua_State *)
static int l_cf_pm_show_context_menu (lua_State *)
static int l_cf_find_focus (lua_State *)
static int l_cf_find_next (lua_State *)
static int l_cf_find_prev (lua_State *)
static int l_cf_find_replace (lua_State *)
static int l_cf_find_replace_all (lua_State *)
static int l_cf_ce_focus (lua_State *)
static int l_cf_ce_show_completions (lua_State *)
int l_init (int argc, char **argv, int reinit)
int l_load_script (const char *script_file)
static GtkWidget * l_checkview (lua_State *lua, int narg)
void l_add_scintilla_window (GtkWidget *editor)
void l_remove_scintilla_window (GtkWidget *editor)
void l_goto_scintilla_window (GtkWidget *editor, int n, int absolute)
void l_set_view_global (GtkWidget *editor)
static sptr_t l_checkdocpointer (lua_State *lua, int narg)
int l_add_scintilla_buffer (sptr_t doc)
void l_remove_scintilla_buffer (sptr_t doc)
unsigned int l_get_docpointer_index (sptr_t doc)
void l_goto_scintilla_buffer (GtkWidget *editor, int n, int absolute)
void l_set_buffer_global (GtkWidget *editor)
void l_close ()
int l_ista2function (const char *table, const char *key)
static int l_call_function (int nargs, int retn, int keep_return)
static int l_rawgeti_int (lua_State *lua, int index, int n)
static const char * l_rawget_str (lua_State *lua, int index, const char *k)
GtkWidget * l_create_gtkmenu (lua_State *lua, GCallback callback, int submenu)
static long l_toscintillaparam (lua_State *lua, int type, int *arg_idx)
static void l_check_focused_buffer (lua_State *lua, int narg)
int l_handle_event (const char *s,...)
void l_handle_scnnotification (struct SCNotification *n)
void l_ta_popup_context_menu (GdkEventButton *event)
int l_pm_pathtableref (GtkTreeStore *store, GtkTreePath *path)
void l_pm_popup_context_menu (GdkEventButton *event)
static int l_call_scintilla (lua_State *lua, GtkWidget *editor, int msg, int p1_type, int p2_type, int rt_type, int arg)
static int l_call_buffer_function (lua_State *lua)
static int l_bufferp_mt_ (lua_State *lua, int n, const char *prop, int arg)
void l_create_entry (lua_State *lua, GtkWidget *c1, GtkWidget *c2, int vertical)
static int l_cf_ta_goto_ (lua_State *lua, GtkWidget *editor, int buffer)
static void t_menu_activate (GtkWidget *menu, gpointer id)
static void pm_menu_activate (GtkWidget *menu, gpointer id)

Variables

lua_State * lua
int closing = FALSE
static int tVOID = 0
static int tLENGTH = 2
static int tBOOL = 5
static int tKEYMOD = 6
static int tSTRING = 7
static int tSTRINGRESULT = 8

Define Documentation

#define child1 (  )     gtk_paned_get_child1(GTK_PANED(p))
#define child2 (  )     gtk_paned_get_child2(GTK_PANED(p))
#define editor_dpi ( editor   )     l_get_docpointer_index(SS(editor, SCI_GETDOCPOINTER, 0, 0))
#define l_append ( l,
 )     lua_rawseti(l, i, lua_objlen(l, i) + 1)
#define l_archive ( l,
 ) 
Value:
{ \
  lua_pushstring(l, k); \
  lua_rawget(l, -2); \
  lua_setfield(l, LUA_REGISTRYINDEX, k); \
  lua_pushstring(l, k); \
  lua_pushnil(l); \
  lua_rawset(l, -3); \
}
#define l_cfunc ( l,
f,
 ) 
Value:
{ \
  lua_pushcfunction(l, f); \
  lua_setfield(l, -2, k); \
}
#define l_insert ( l,
 )     lua_insert(l, (i < 0) ? lua_gettop(l) + i : i)
#define l_mt ( l,
k,
i,
ni   ) 
Value:
{ \
  if (luaL_newmetatable(l, k)) { \
    l_cfunc(l, i, "__index"); \
    l_cfunc(l, ni, "__newindex"); \
  } \
  lua_setmetatable(l, -2); \
}
#define l_pushscninteger ( i,
 ) 
Value:
{ \
  lua_pushinteger(lua, i); \
  lua_setfield(lua, -2, n); \
}
#define l_togtkwidget ( l,
 )     (GtkWidget *)lua_touserdata(l, i)
#define streq ( s1,
s2   )     strcmp(s1, s2) == 0
#define toggle ( w,
 )     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), b)
#define toggled (  )     gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))

Function Documentation

static void clear_table ( lua_State *  lua,
int  abs_index 
) [static]

Recurses through a Lua table, setting each of its keys and values to nil, effectively clearing the table.

Parameters:
lua The Lua State.
abs_index The absolute stack index of the table to clear.
int l_add_scintilla_buffer ( sptr_t  doc  ) 

Adds a Scintilla document to the global 'buffers' table with a metatable.

Parameters:
doc The Scintilla document to add.
Returns:
integer index of the new buffer in textadept.buffers.
void l_add_scintilla_window ( GtkWidget *  editor  ) 

Adds a Scintilla window to the global 'views' table with a metatable.

Parameters:
editor The Scintilla window to add.
static int l_buffer_mt_index ( lua_State *  lua  )  [static]

Metatable index for a buffer table. If the key is a Scintilla buffer function, push a closure so it can be called as a function. If the key is a non-indexable buffer property, call Scintilla to get it. If the key is an indexible buffer property, push a table with a metatable to access buffer property indices.

Parameters:
lua The Lua State.
static int l_buffer_mt_newindex ( lua_State *  lua  ) 
static int l_bufferp_mt_ ( lua_State *  lua,
int  n,
const char *  prop,
int  arg 
) [static]

Helper function for the buffer property metatable. Throws an error when trying to write to a read-only property or when trying to read a write-only property.

Parameters:
lua The Lua State.
n 1 for getter property, 2 for setter.
prop String property name.
arg The index on the Lua stack where arguments to Scintilla begin. For setter properties, it is 3 because the index is not an argument. For getter and setter properties, it is 2 because the index is an argument.
static int l_bufferp_mt_index ( lua_State *  lua  ) 
static int l_bufferp_mt_newindex ( lua_State *  lua  ) 
static int l_call_buffer_function ( lua_State *  lua  )  [static]

Calls a Scintilla buffer function with upvalues from a closure.

Parameters:
lua The Lua State.
See also:
l_buffer_mt_index
static int l_call_function ( int  nargs,
int  retn,
int  keep_return 
) [static]

Calls a Lua function with a number of arguments and expected return values. The last argument is at the stack top, and each argument in reverse order is one element lower on the stack with the Lua function being under the first argument.

Parameters:
nargs The number of arguments to pass to the Lua function to call.
retn Optional number of expected return values. Defaults to 0.
keep_return Optional flag indicating whether or not to keep the return values at the top of the stack. If FALSE, discards the return values. Defaults to FALSE.
static int l_call_scintilla ( lua_State *  lua,
GtkWidget *  editor,
int  msg,
int  p1_type,
int  p2_type,
int  rt_type,
int  arg 
) [static]

Calls Scintilla with appropriate parameters and returs appropriate values.

Parameters:
lua The Lua State.
editor The Scintilla window to call.
msg The integer message index to call Scintilla with.
p1_type The Lua type of p1, the Scintilla w parameter.
p2_type The Lua type of p2, the Scintilla l parameter.
rt_type The Lua type of the Scintilla return parameter.
arg The index on the Lua stack where arguments to Scintilla begin.
static int l_ce_mt_index ( lua_State *  lua  ) 
static int l_ce_mt_newindex ( lua_State *  lua  ) 
static int l_cf_buffer_delete ( lua_State *  lua  )  [static]
static int l_cf_buffer_text_range ( lua_State *  lua  ) 
static int l_cf_ce_focus ( lua_State *  lua  ) 
static int l_cf_ce_show_completions ( lua_State *  lua  ) 
static int l_cf_find_focus ( lua_State *  lua  ) 
static int l_cf_find_next ( lua_State *  lua  ) 
static int l_cf_find_prev ( lua_State *  lua  ) 
static int l_cf_find_replace ( lua_State *  lua  ) 
static int l_cf_find_replace_all ( lua_State *  lua  ) 
static int l_cf_pm_activate ( lua_State *  lua  ) 
static int l_cf_pm_add_browser ( lua_State *  lua  ) 
static int l_cf_pm_clear ( lua_State *  lua  ) 
static int l_cf_pm_fill ( lua_State *  lua  ) 
static int l_cf_pm_focus ( lua_State *  lua  ) 
static int l_cf_pm_show_context_menu ( lua_State *  lua  ) 
static int l_cf_ta_buffer_new ( lua_State *  lua  ) 
static int l_cf_ta_dialog ( lua_State *  lua  ) 
static int l_cf_ta_get_split_table ( lua_State *  lua  ) 
static int l_cf_ta_goto_ ( lua_State *  lua,
GtkWidget *  editor,
int  buffer 
) [static]
static int l_cf_ta_goto_window ( lua_State *  lua  ) 
static int l_cf_ta_gtkmenu ( lua_State *  lua  ) 
static int l_cf_ta_iconv ( lua_State *  lua  ) 
static int l_cf_ta_quit ( lua_State *  lua  ) 
static int l_cf_ta_reset ( lua_State *  lua  ) 
static int l_cf_view_focus ( lua_State *  lua  ) 
static int l_cf_view_goto_buffer ( lua_State *  lua  ) 
static int l_cf_view_split ( lua_State *  lua  ) 
static int l_cf_view_unsplit ( lua_State *  lua  ) 
static void l_check_focused_buffer ( lua_State *  lua,
int  narg 
) [static]

Checks if the Scintilla document of the buffer table at the index specified is the document of the focused Scintilla window. Throws an error if the check is not satisfied.

Parameters:
lua The Lua State.
narg The relative stack position of the buffer table.
static sptr_t l_checkdocpointer ( lua_State *  lua,
int  narg 
) [static]

Checks a specified element to see if it is a buffer table and returns the Scintilla document pointer associated with it. Throws an error if the check is not satisfied.

Parameters:
lua The Lua State.
narg Relative stack index to check for a buffer table.
static GtkWidget* l_checkview ( lua_State *  lua,
int  narg 
) [static]

Checks a specified stack element to see if it is a Scintilla window and returns it as a GtkWidget. Throws an error if the check is not satisfied.

Parameters:
lua The Lua State.
narg Relative stack index to check for a Scintilla window.
void l_close (  ) 

Closes the Lua State. Unsplits all Scintilla windows recursively, removes all Scintilla documents, and deletes the last Scintilla window before closing the state.

void l_create_entry ( lua_State *  lua,
GtkWidget *  c1,
GtkWidget *  c2,
int  vertical 
)
GtkWidget* l_create_gtkmenu ( lua_State *  lua,
GCallback  callback,
int  submenu 
)

Creates a GtkMenu from a table at the top of the Lua stack. The table has a key 'title' and a numeric list of subitems.

Parameters:
lua The Lua State.
callback A GCallback associated with each menu item.
submenu Flag indicating whether or not this menu is a submenu.
static int l_find_mt_index ( lua_State *  lua  ) 
static int l_find_mt_newindex ( lua_State *  lua  ) 
unsigned int l_get_docpointer_index ( sptr_t  doc  ) 

Retrieves the index in the global 'buffers' table for a given Scintilla document.

Parameters:
doc The Scintilla document to get the index of.
void l_goto_scintilla_buffer ( GtkWidget *  editor,
int  n,
int  absolute 
)

Changes a Scintilla window's document to one in the global 'buffers' table. Before doing so, it saves the scroll and caret positions in the current Scintilla document. Then when the new document is shown, its scroll and caret positions are restored.

Parameters:
editor The Scintilla window to change the document of.
n The index of the document in 'buffers' to focus.
absolute Flag indicating whether or not the index specified in 'views' is absolute. If FALSE, focuses the document relative to the currently focused document for the given index. Throws an error if the buffer does not exist.
void l_goto_scintilla_window ( GtkWidget *  editor,
int  n,
int  absolute 
)

Changes focus a Scintilla window in the global 'views' table.

Parameters:
editor The currently focused Scintilla window.
n The index of the window in the 'views' table to focus.
absolute Flag indicating whether or not the index specified in 'views' is absolute. If FALSE, focuses the window relative to the currently focused window for the given index. Throws an error if the view does not exist.
int l_handle_event ( const char *  s,
  ... 
)

Handles a Textadept event.

Parameters:
s String event name.
... Optional arguments to pass to the handler. The variable argument list should contain Lua types followed by the data of that type to pass. The list is terminated by a -1.
void l_handle_scnnotification ( struct SCNotification *  n  ) 

Handles a Scintilla notification.

Parameters:
n The Scintilla notification struct.
int l_init ( int  argc,
char **  argv,
int  reinit 
)

Inits or re-inits the Lua State. Populates the state with global variables and functions, then runs the 'core/init.lua' script.

Parameters:
argc The number of command line parameters.
argv The array of command line parameters.
reinit Flag indicating whether or not to reinitialize the Lua State.
int l_ista2function ( const char *  table,
const char *  key 
)

Returns whether or not the value of the key of the given table in the global 'textadept' table is a function.

Parameters:
table The table in 'textadept' to check for key in.
key String key to check for in table.
int l_load_script ( const char *  script_file  ) 

Loads and runs a given Lua script.

Parameters:
script_file The path of the Lua script relative to textadept_home.
static int l_pm_mt_index ( lua_State *  lua  ) 
static int l_pm_mt_newindex ( lua_State *  lua  ) 
int l_pm_pathtableref ( GtkTreeStore *  store,
GtkTreePath *  path 
)

Creates a Lua table of parent nodes for the given Project Manager treeview path and returns a reference to it. The first table item is the PM Entry text, the next items are parents of the given node in descending order, and the last item is the given node itself. The reference can be retrieved using lua_rawgeti.

Parameters:
store The GtkTreeStore of the PM view.
path The GtkTreePath of the node. If NULL, only the PM Entry text is contained in the resulting table.
Returns:
int reference to the created table in LUA_REGISTRYINDEX.
void l_pm_popup_context_menu ( GdkEventButton *  event  ) 

Requests a popup context menu for a selected Project Manager item.

Parameters:
event The mouse button event.
static const char* l_rawget_str ( lua_State *  lua,
int  index,
const char *  k 
) [static]

Performs a Lua rawget on a table at a given stack index and returns a string.

Parameters:
lua The Lua State.
index The relative index of the table to rawget from.
k String key in the table to rawget.
static int l_rawgeti_int ( lua_State *  lua,
int  index,
int  n 
) [static]

Performs a Lua rawget on a table at a given stack index and returns an int.

Parameters:
lua The Lua State.
index The relative index of the table to rawget from.
n The index in the table to rawget.
void l_remove_scintilla_buffer ( sptr_t  doc  ) 

Removes a Scintilla document from the global 'buffers' table. If any views currently show the document to be removed, change the documents they show first.

Parameters:
doc The Scintilla buffer to remove.
void l_remove_scintilla_window ( GtkWidget *  editor  ) 

Removes a Scintilla window from the global 'views' table.

Parameters:
editor The Scintilla window to remove.
void l_set_buffer_global ( GtkWidget *  editor  ) 

Sets the global 'buffer' variable to be the document in the specified Scintilla object.

Parameters:
editor The Scintilla widget housing the buffer to be 'buffer'.
void l_set_view_global ( GtkWidget *  editor  ) 

Sets the global 'view' variable to be the specified Scintilla window.

Parameters:
editor The Scintilla window to set 'view' to.
static int l_ta_mt_index ( lua_State *  lua  ) 
static int l_ta_mt_newindex ( lua_State *  lua  ) 
void l_ta_popup_context_menu ( GdkEventButton *  event  ) 

Requests and pops up a context menu for the Scintilla view.

Parameters:
event The mouse button event.
static long l_toscintillaparam ( lua_State *  lua,
int  type,
int *  arg_idx 
) [static]

Convert the stack element at a specified index to a Scintilla w and/or l long parameter based on type.

Parameters:
lua The Lua State.
type The Lua type the top stack element is.
arg_idx The initial stack index to start converting at. It is incremented as parameters are read from the stack.
static int l_view_mt_index ( lua_State *  lua  ) 
static int l_view_mt_newindex ( lua_State *  lua  ) 
static void pm_menu_activate ( GtkWidget *  menu,
gpointer  id 
) [static]
static void t_menu_activate ( GtkWidget *  menu,
gpointer  id 
) [static]
static void warn ( const char *  s  )  [static]

Variable Documentation

int closing = FALSE
lua_State* lua
int tBOOL = 5 [static]
int tKEYMOD = 6 [static]
int tLENGTH = 2 [static]
int tSTRING = 7 [static]
int tSTRINGRESULT = 8 [static]
int tVOID = 0 [static]

Generated by  doxygen 1.6.2