Elua(3)

NAME
Elua - Elua

SYNOPSIS

  Typedefs
typedef struct _Elua_State Elua_State
Opaque Elua state.

  Functions
EAPI int elua_init (void)
Initialize the Elua library.
EAPI int elua_shutdown (void)
Shutdown the Elua library.
EAPI Elua_State * elua_state_new (const char *progname)
Create a new Elua state.
EAPI Elua_State * elua_state_from_lua_state_get (lua_State *L)
Retrieve an Elua state from a Lua state.
EAPI void elua_state_free (Elua_State *es)
Destroy an Elua state.
EAPI void elua_state_dirs_set (Elua_State *es, const char *core, const char *mods, const char *apps)
Set the Elua directory paths.
EAPI void elua_state_dirs_fill (Elua_State *es, Eina_Bool ignore_env)
Fill the currently unset Elua dirs.
EAPI Eina_Stringshare * elua_state_core_dir_get (const Elua_State *es)
Retrieve the Elua core dir.
EAPI Eina_Stringshare * elua_state_mod_dir_get (const Elua_State *es)
Retrieve the Elua module dir.
EAPI Eina_Stringshare * elua_state_apps_dir_get (const Elua_State *es)
Retrieve the Elua apps dir.
EAPI Eina_Stringshare * elua_state_prog_name_get (const Elua_State *es)
Retrieve the prog name set on state creation.
EAPI void elua_state_include_path_add (Elua_State *es, const char *path)
Add another path to look up modules in to the state.
EAPI Eina_Bool elua_state_require_ref_push (Elua_State *es)
Push the Elua 'require' function onto the Lua stack.
EAPI Eina_Bool elua_state_appload_ref_push (Elua_State *es)
Push the Elua app loader function onto the Lua stack.
EAPI lua_State * elua_state_lua_state_get (const Elua_State *es)
Retrieve the Lua state from an Elua state.
EAPI Eina_Bool elua_state_setup (Elua_State *es)
Set up the Elua state.
EAPI int elua_io_loadfile (const Elua_State *es, const char *fname)
Loads a file using Elua's own mmap-based IO.
EAPI Eina_Bool elua_util_require (Elua_State *es, const char *libname)
Requires a module.
EAPI Eina_Bool elua_util_file_run (Elua_State *es, const char *fname)
Runs a file.
EAPI Eina_Bool elua_util_string_run (Elua_State *es, const char *chunk, const char *chname)
Runs a string.
EAPI int elua_util_app_load (Elua_State *es, const char *appname)
Loads an application.
EAPI Eina_Bool elua_util_script_run (Elua_State *es, int argc, char **argv, int n, int *quit)
Runs a script.
EAPI int elua_util_error_report (const Elua_State *es, int status)
Reports an error using Eina logging.

Detailed Description

Function Documentation

  EAPI int elua_init (void)

Initialize the Elua library. This initializes the Elua library for usage. It maintains an internal counter so that multiple calls will only increment/decrement correctly.

See also
    elua_shutdown

References ecore_file_init(), EINA_FALSE, eina_init(), eina_log_domain_register(), EINA_LOG_ERR, EINA_LOG_STATE_INIT, EINA_LOG_STATE_STOP, eina_log_timing(), eina_prefix_new(), ERR, and INF.

  EAPI int elua_shutdown (void)

Shutdown the Elua library. Depending on the internal initialization counter, this either decrements or completely shuts down the Elua library. In any case, call this once for each init call.

See also
    elua_init

References ecore_file_shutdown(), EINA_FALSE, eina_log_domain_unregister(), EINA_LOG_ERR, EINA_LOG_STATE_SHUTDOWN, EINA_LOG_STATE_START, eina_log_timing(), eina_prefix_free(), eina_shutdown(), and INF.

  EAPI Elua_State* elua_state_new (const char * progname)

Create a new Elua state. This creates a new Elua state. An Elua state is externally opaque, but it contains a LuaJIT state as well as some additional information that is mostly initialized by other APIs.

Parameters
    progname The program name that holds the Elua state. This will be used for stuff like error reporting. Typically the same as the binary name of the application (argv[0]).

Returns
    A new Elua state or NULL.

References eina_stringshare_add(), eina_stringshare_del(), and ERR.

  EAPI Elua_State* elua_state_from_lua_state_get (lua_State * L)

Retrieve an Elua state from a Lua state. This doesn't create a new Elua state. Instead it just retrieves an existing Elua state given a Lua state. If no Elua state could be found (for example when the Lua state was created independently of Elua), this function returns NULL.

Parameters
    L The Lua state.

Returns
    An Elua state or NULL.

References EINA_SAFETY_ON_NULL_RETURN_VAL.

  EAPI void elua_state_free (Elua_State * es)

Destroy an Elua state. Given an Elua state, this destroys its internal Lua state as well as all other data its holding and then frees the Elua state itself.

Parameters
    es The Elua state.

References eina_list_free(), EINA_LIST_FREE, and eina_stringshare_del().

  EAPI void elua_state_dirs_set (Elua_State * es, const char * core, const char * mods, const char * apps)

Set the Elua directory paths. Every Elua state needs three paths - the core script path, the module path and the apps path. The core path refers to from where core scripts will be loaded (such as the module system), the module path refers to from where extra modules will be loaded and the apps path refers to from where Elua applications will be loaded (this is not a module path).

If you provide NULL for any path, it will not be set. This allows you to split the setting into multiple calls. By the time of state use all need to be set.

Also, all the paths will be sanitized before setting by calling eina_file_path_sanitize on them.

Parameters
    es The Elua state.
    core The core path.
    mods The modules path.
    apps The apps path.

See also
    elua_state_core_dir_get

    elua_state_mod_dir_get

    elua_state_apps_dir_get

References eina_file_path_sanitize(), EINA_SAFETY_ON_NULL_RETURN, eina_stringshare_add(), and eina_stringshare_del().

  EAPI void elua_state_dirs_fill (Elua_State * es, Eina_Bool ignore_env)

Fill the currently unset Elua dirs. This checks if any of the three main paths are unset and tries to fill them from the environment. It first tries environment variables to fill them (ELUA_CORE_DIR, ELUA_MODULES_DIR, ELUA_APPS_DIR) unless the ignore_env param is EINA_TRUE. If it is (or if the environment vars weren't set right) it uses eina prefix of the library to determine the paths. In that case they will expand to DATADIR/core, DATADIR/modules and DATADIR/apps, where DATADIR is typically something like /usr/share/elua.

Also, all the paths will be sanitized before setting by calling eina_file_path_sanitize on them.

Parameters
    es The Elua state.
    ignore_env If set to EINA_TRUE, this ignores the env vars.

  EAPI Eina_Stringshare* elua_state_core_dir_get (const Elua_State * es)

Retrieve the Elua core dir.

Parameters
    es The Elua state.

Returns
    The path.

References EINA_SAFETY_ON_NULL_RETURN_VAL.

  EAPI Eina_Stringshare* elua_state_mod_dir_get (const Elua_State * es)

Retrieve the Elua module dir.

Parameters
    es The Elua state.

Returns
    The path.

References EINA_SAFETY_ON_NULL_RETURN_VAL.

  EAPI Eina_Stringshare* elua_state_apps_dir_get (const Elua_State * es)

Retrieve the Elua apps dir.

Parameters
    es The Elua state.

Returns
    The path.

References EINA_SAFETY_ON_NULL_RETURN_VAL.

  EAPI Eina_Stringshare* elua_state_prog_name_get (const Elua_State * es)

Retrieve the prog name set on state creation.

Parameters
    es The Elua state.

Returns
    The name.

References EINA_SAFETY_ON_NULL_RETURN_VAL.

  EAPI void elua_state_include_path_add (Elua_State * es, const char * path)

Add another path to look up modules in to the state. The path will be sanitized using eina_file_path_sanitize.

Parameters
    es The Elua state.

References eina_file_path_sanitize(), eina_list_append(), EINA_SAFETY_ON_FALSE_RETURN, EINA_SAFETY_ON_NULL_RETURN, and eina_stringshare_add().

  EAPI Eina_Bool elua_state_require_ref_push (Elua_State * es)

Push the Elua 'require' function onto the Lua stack.

Parameters
    es The Elua state.

Returns
    EINA_TRUE if the push was successful, EINA_FALSE otherwise.

References EINA_FALSE, EINA_SAFETY_ON_FALSE_RETURN_VAL, EINA_SAFETY_ON_NULL_RETURN_VAL, and EINA_TRUE.

Referenced by elua_state_setup(), and elua_util_require().

  EAPI Eina_Bool elua_state_appload_ref_push (Elua_State * es)

Push the Elua app loader function onto the Lua stack.

Parameters
    es The Elua state.

Returns
    EINA_TRUE if the push was successful, EINA_FALSE otherwise.

References EINA_FALSE, EINA_SAFETY_ON_FALSE_RETURN_VAL, EINA_SAFETY_ON_NULL_RETURN_VAL, and EINA_TRUE.

Referenced by elua_util_app_load().

  EAPI lua_State* elua_state_lua_state_get (const Elua_State * es)

Retrieve the Lua state from an Elua state. This function retrieves the Lua state from a valid Elua state. As an Elua state is always initialized, this will return a valid state, unless the given Elua state is NULL, in which case it will also return NULL.

Parameters
    es The Elua state.

Returns
    The Lua state or NULL.

References EINA_SAFETY_ON_NULL_RETURN_VAL.

  EAPI Eina_Bool elua_state_setup (Elua_State * es)

Set up the Elua state. This API function sets up 3 things, module system, i18n and I/O. After that it requires all modules not yet required (i.e. those queued in before the state was fully initialized).

This function sets up correct i18n for an Elua state. That means loading the gettext bindings and making Lua aware of them. This also works when i18n support is disabled at compilation time, so you can just call it unconditionally.

This also loads the Elua module system and makes Lua aware of it. It also registers the Elua C utility library module.

Finally, Elua provides its own loadfile based around mmap to replace the less efficient Lua version. This function takes care of the setup.

Parameters
    es The Elua state.

Returns
    EINA_TRUE on success, EINA_FALSE on failure.

References EINA_FALSE, EINA_LIST_FREE, eina_stringshare_del(), EINA_TRUE, elua_state_require_ref_push(), and elua_util_error_report().

  EAPI int elua_io_loadfile (const Elua_State * es, const char * fname)

Loads a file using Elua's own mmap-based IO. This function behaves identically to luaL_loadfile when it comes to semantics. The loaded file remains on the Lua stack. If the input state is NULL, the return value is -1 and nothing is left on the stack. On any different error, the error object is left on the stack and this returns a value larger than zero (LUA_ERR*). On success, zero is returned.

Parameters
    es The Elua state.
    fname The file name.

Returns
    0 for no errors, a non-zero value for errors (-1 for NULL es).

References EINA_FALSE, eina_file_close(), eina_file_map_all(), eina_file_map_free(), EINA_FILE_RANDOM, eina_file_size_get(), and EINA_TRUE.

Referenced by elua_util_file_run(), and elua_util_script_run().

  EAPI Eina_Bool elua_util_require (Elua_State * es, const char * libname)

Requires a module. Requires a Lua module. Leaves the Lua stack clean.

Parameters
    es The Elua state.
    libname The library name.

Returns
    EINA_TRUE on success, EINA_FALSE on failure.

References EINA_FALSE, eina_list_append(), EINA_SAFETY_ON_NULL_RETURN_VAL, eina_stringshare_add(), elua_state_require_ref_push(), and elua_util_error_report().

  EAPI Eina_Bool elua_util_file_run (Elua_State * es, const char * fname)

Runs a file. Runs a file. Uses the Elua mmapped file IO to load the file.

Parameters
    es The Elua state.
    fname The file name.

Returns
    EINA_TRUE on success, EINA_FALSE on failure.

References EINA_FALSE, EINA_SAFETY_ON_NULL_RETURN_VAL, elua_io_loadfile(), and elua_util_error_report().

  EAPI Eina_Bool elua_util_string_run (Elua_State * es, const char * chunk, const char * chname)

Runs a string. Runs a string.

Parameters
    es The Elua state.
    chunk The string to run.
    chname The chunk name to use for traceback/debug.

Returns
    EINA_TRUE on success, EINA_FALSE on failure.

References EINA_FALSE, EINA_SAFETY_ON_NULL_RETURN_VAL, and elua_util_error_report().

  EAPI int elua_util_app_load (Elua_State * es, const char * appname)

Loads an application. This loads an app, respecting the app path set on state initialization. Actually runs the app. If the input state is NULL, the return value is -1 nd nothing is left on the stack. On any different error, the error object is left on the stack and this returns 1. On success, zero is returned (and the return value from the app is left on the stack).

Parameters
    es The Elua state.
    appname The application name.

Returns
    0 for no errors, 1 on errors, -1 on null input.

References EINA_SAFETY_ON_FALSE_RETURN_VAL, EINA_SAFETY_ON_NULL_RETURN_VAL, and elua_state_appload_ref_push().

Referenced by elua_util_script_run().

  EAPI Eina_Bool elua_util_script_run (Elua_State * es, int argc, char ** argv, int n, int * quit)

Runs a script. This is a more complicated function that runs a script. It's a combination of the previously mentioned util functions. It takes argc and argv, which are typically given to the program, and an index of the first positional arg in argv (i.e. not options). The value on this index is then used as the potential name.

If this name is either a dash or empty, the script is loaded from stdin. If it's a value and a file with this name exists, the script is loaded from the file. Otherwise, the name is treated to be an application name, and is loaded from the application path.

If all succeeds, this is then run, and a quit value is written into the quit arg; if it's true (1), it means the app wants to exit immediately. If it's false (0), it means the app likely wants to execute a main loop.

Parameters
    es The Elua state.
    argc The argument count.
    argv The arguments.
    n The index of the first positional argt.
    quit Whether to quit or run a main loop.

Returns
    EINA_TRUE on success, EINA_FALSE on failure.

References EINA_SAFETY_ON_FALSE_RETURN_VAL, EINA_SAFETY_ON_NULL_RETURN_VAL, elua_io_loadfile(), elua_util_app_load(), and elua_util_error_report().

  EAPI int elua_util_error_report (const Elua_State * es, int status)

Reports an error using Eina logging. If the given status is 0, this function just returns it. Otherwise, it takes the topmost item on the Lua stack, converts it to string (if it cannot be converted, a '(non-string error)' placeholder is used) and logs it out as an error, together with the program name set on Elua state init.

Parameters
    es The Elua state.
    status The status code.

Returns
    The status code.

References EINA_SAFETY_ON_FALSE_RETURN_VAL.

Referenced by elua_state_setup(), elua_util_file_run(), elua_util_require(), elua_util_script_run(), and elua_util_string_run().

Author

Generated automatically by Doxygen for EFL from the source code.