xaizek / vifm (License: GPLv2+) (since 2018-12-07)
Vifm is a file manager with curses interface, which provides Vi[m]-like environment for managing objects within file systems, extended with some useful ideas from mutt.
<root> / src / lua / common.h (acd6a2219fa5126f63a2746eddcb3c2c273168af) (3,809B) (mode 100644) [raw]
/* vifm
 * Copyright (C) 2020 xaizek.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 */

#ifndef VIFM__LUA__COMMON_H__
#define VIFM__LUA__COMMON_H__

struct lua_State;
struct view_t;

/* Retrieves optional argument while checking its type and aborting (Lua does
 * longjmp()) if it doesn't match.  Returns non-zero if the argument is present
 * and is of correct type. */
int vlua_cmn_check_opt_arg(struct lua_State *lua, int arg_idx,
		int expected_type);

/* Retrieves mandatory field of a table while checking its type and aborting
 * (Lua does longjmp()) if it's missing or doesn't match. */
void vlua_cmn_check_field(struct lua_State *lua, int table_idx,
		const char name[], int lua_type);

/* Retrieves optional field of a table while checking its type and aborting (Lua
 * does longjmp()) if it doesn't match.  Returns non-zero if the field is
 * present and is of correct type. */
int vlua_cmn_check_opt_field(struct lua_State *lua, int table_idx,
		const char name[], int lua_type);

/* Retrieves user data from a specified stack index aborting (Lua does
 * longjmp()) if it's missing or isn't user data.  Returns user data pointer,
 * never NULL. */
void * vlua_cmn_check_this(struct lua_State *lua, int idx);

/* Converts Lua value at the top of the stack into a C pointer without popping
 * it.  Returns the pointer. */
void * vlua_cmn_to_pointer(struct lua_State *lua);

/* Associates value at the top of Lua stack with the pointer value for future
 * lookup via vlua_cmn_from_pointer(). */
void vlua_cmn_set_pointer(struct lua_State *lua, void *key);

/* Converts C pointer to a Lua value and pushes it on top of the stack. */
void vlua_cmn_from_pointer(struct lua_State *lua, void *ptr);

/* Removes pointer stored by vlua_cmn_to_pointer(). */
void vlua_cmn_drop_pointer(struct lua_State *lua, void *ptr);

struct opt_t;

/* Reads option value as a Lua value.  Returns number of results. */
int vlua_cmn_get_opt(struct lua_State *lua, struct opt_t *opt);

/* Sets option value from a Lua value.  Returns number of results, which is
 * always zero. */
int vlua_cmn_set_opt(struct lua_State *lua, struct opt_t *opt);

/* Creates an array of strings and leaves it on the top of the stack. */
void vlua_cmn_push_str_array(struct lua_State *lua, char *array[], int len);

/* Creates a metatable whose __index points to itself and which is opaque for
 * Lua code (can't be read or set).  If name is NULL, the metatable isn't stored
 * in the registry.  The metatable is left on the top of the stack. */
void vlua_cmn_make_metatable(struct lua_State *lua, const char name[]);

/* Extracts selected indexes from "indexes" field of the table at the top of Lua
 * stack.  For valid "indexes" field, allocates an array, which should be freed
 * by the caller.  Indexes are sorted and deduplicated.  Returns zero on success
 * (valid "indexes" field) and non-zero on error. */
int vlua_cmn_extract_indexes(struct lua_State *lua, struct view_t *view,
		int *count, int *indexes[]);

#endif /* VIFM__LUA__COMMON_H__ */

/* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */
/* vim: set cinoptions+=t0 : */
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/vifm

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/vifm

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master