forked from enlightenment/efl
elua lib: unify API conventions
This commit is contained in:
parent
eea537ded3
commit
d8890209af
|
@ -110,11 +110,10 @@ elua_main(lua_State *L)
|
||||||
elua_state_dirs_set(es, coredir, moddir, appsdir);
|
elua_state_dirs_set(es, coredir, moddir, appsdir);
|
||||||
elua_state_dirs_fill(es, noenv);
|
elua_state_dirs_fill(es, noenv);
|
||||||
|
|
||||||
if (!elua_state_setup_modules(es) || !elua_state_setup_i18n(es))
|
if (!elua_state_modules_setup(es) || !elua_state_i18n_setup(es)
|
||||||
|
|| !elua_state_io_setup(es))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
elua_io_register(es);
|
|
||||||
|
|
||||||
lua_gc(L, LUA_GCRESTART, 0);
|
lua_gc(L, LUA_GCRESTART, 0);
|
||||||
|
|
||||||
INF("elua lua state initialized");
|
INF("elua lua state initialized");
|
||||||
|
|
|
@ -87,15 +87,15 @@ EAPI Eina_Bool elua_state_appload_ref_push(Elua_State *es);
|
||||||
|
|
||||||
EAPI lua_State *elua_state_lua_state_get(const Elua_State *es);
|
EAPI lua_State *elua_state_lua_state_get(const Elua_State *es);
|
||||||
|
|
||||||
EAPI int elua_report_error(const Elua_State *es, const char *pname, int status);
|
EAPI int elua_error_report(const Elua_State *es, const char *pname, int status);
|
||||||
|
|
||||||
EAPI Eina_Bool elua_state_setup_i18n(const Elua_State *es);
|
EAPI Eina_Bool elua_state_i18n_setup(const Elua_State *es);
|
||||||
EAPI Eina_Bool elua_state_setup_modules(const Elua_State *es);
|
EAPI Eina_Bool elua_state_modules_setup(const Elua_State *es);
|
||||||
|
EAPI Eina_Bool elua_state_io_setup(const Elua_State *es);
|
||||||
|
|
||||||
EAPI int elua_io_loadfile(const Elua_State *es, const char *fname);
|
EAPI int elua_io_loadfile(const Elua_State *es, const char *fname);
|
||||||
EAPI void elua_io_register(const Elua_State *es);
|
|
||||||
|
|
||||||
EAPI int elua_io_popen(lua_State *L);
|
EAPI int elua_io_popen(lua_State *L);
|
||||||
|
|
||||||
EAPI int elua_module_init(lua_State *L);
|
EAPI int elua_module_init(lua_State *L);
|
||||||
EAPI int elua_module_system_init(lua_State *L);
|
EAPI int elua_module_system_init(lua_State *L);
|
||||||
|
|
||||||
|
|
|
@ -208,10 +208,11 @@ loadfile(lua_State *L)
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI void
|
EAPI Eina_Bool
|
||||||
elua_io_register(const Elua_State *es)
|
elua_state_io_setup(const Elua_State *es)
|
||||||
{
|
{
|
||||||
EINA_SAFETY_ON_FALSE_RETURN(es && es->luastate);
|
EINA_SAFETY_ON_FALSE_RETURN_VAL(es && es->luastate, EINA_FALSE);
|
||||||
lua_pushcfunction(es->luastate, loadfile);
|
lua_pushcfunction(es->luastate, loadfile);
|
||||||
lua_setglobal(es->luastate, "loadfile");
|
lua_setglobal(es->luastate, "loadfile");
|
||||||
|
return EINA_TRUE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -237,7 +237,7 @@ _elua_errmsg(const char *pname, const char *msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI int
|
EAPI int
|
||||||
elua_report_error(const Elua_State *es, const char *pname, int status)
|
elua_error_report(const Elua_State *es, const char *pname, int status)
|
||||||
{
|
{
|
||||||
EINA_SAFETY_ON_FALSE_RETURN_VAL(es && es->luastate, status);
|
EINA_SAFETY_ON_FALSE_RETURN_VAL(es && es->luastate, status);
|
||||||
if (status && !lua_isnil(es->luastate, -1))
|
if (status && !lua_isnil(es->luastate, -1))
|
||||||
|
@ -284,7 +284,7 @@ const luaL_reg gettextlib[] =
|
||||||
};
|
};
|
||||||
|
|
||||||
EAPI Eina_Bool
|
EAPI Eina_Bool
|
||||||
elua_state_setup_i18n(const Elua_State *es)
|
elua_state_i18n_setup(const Elua_State *es)
|
||||||
{
|
{
|
||||||
#ifdef ENABLE_NLS
|
#ifdef ENABLE_NLS
|
||||||
char *(*dgettextp)(const char*, const char*) = dgettext;
|
char *(*dgettextp)(const char*, const char*) = dgettext;
|
||||||
|
@ -297,7 +297,7 @@ elua_state_setup_i18n(const Elua_State *es)
|
||||||
EINA_SAFETY_ON_NULL_RETURN_VAL(es->coredir, EINA_FALSE);
|
EINA_SAFETY_ON_NULL_RETURN_VAL(es->coredir, EINA_FALSE);
|
||||||
EINA_SAFETY_ON_NULL_RETURN_VAL(es->progname, EINA_FALSE);
|
EINA_SAFETY_ON_NULL_RETURN_VAL(es->progname, EINA_FALSE);
|
||||||
snprintf(buf, sizeof(buf), "%s/gettext.lua", es->coredir);
|
snprintf(buf, sizeof(buf), "%s/gettext.lua", es->coredir);
|
||||||
if (elua_report_error(es, es->progname, elua_io_loadfile(es, buf)))
|
if (elua_error_report(es, es->progname, elua_io_loadfile(es, buf)))
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
lua_createtable(es->luastate, 0, 0);
|
lua_createtable(es->luastate, 0, 0);
|
||||||
luaL_register(es->luastate, NULL, gettextlib);
|
luaL_register(es->luastate, NULL, gettextlib);
|
||||||
|
@ -319,7 +319,7 @@ const luaL_reg _elua_cutillib[] =
|
||||||
};
|
};
|
||||||
|
|
||||||
EAPI Eina_Bool
|
EAPI Eina_Bool
|
||||||
elua_state_setup_modules(const Elua_State *es)
|
elua_state_modules_setup(const Elua_State *es)
|
||||||
{
|
{
|
||||||
char buf[PATH_MAX];
|
char buf[PATH_MAX];
|
||||||
EINA_SAFETY_ON_NULL_RETURN_VAL(es, EINA_FALSE);
|
EINA_SAFETY_ON_NULL_RETURN_VAL(es, EINA_FALSE);
|
||||||
|
@ -327,7 +327,7 @@ elua_state_setup_modules(const Elua_State *es)
|
||||||
EINA_SAFETY_ON_NULL_RETURN_VAL(es->coredir, EINA_FALSE);
|
EINA_SAFETY_ON_NULL_RETURN_VAL(es->coredir, EINA_FALSE);
|
||||||
EINA_SAFETY_ON_NULL_RETURN_VAL(es->progname, EINA_FALSE);
|
EINA_SAFETY_ON_NULL_RETURN_VAL(es->progname, EINA_FALSE);
|
||||||
snprintf(buf, sizeof(buf), "%s/module.lua", es->coredir);
|
snprintf(buf, sizeof(buf), "%s/module.lua", es->coredir);
|
||||||
if (elua_report_error(es, es->progname, elua_io_loadfile(es, buf)))
|
if (elua_error_report(es, es->progname, elua_io_loadfile(es, buf)))
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
lua_pushcfunction(es->luastate, elua_module_system_init);
|
lua_pushcfunction(es->luastate, elua_module_system_init);
|
||||||
lua_createtable(es->luastate, 0, 0);
|
lua_createtable(es->luastate, 0, 0);
|
||||||
|
@ -453,7 +453,7 @@ elua_util_require(Elua_State *es, const char *libname)
|
||||||
EINA_SAFETY_ON_NULL_RETURN_VAL(es->luastate, -1);
|
EINA_SAFETY_ON_NULL_RETURN_VAL(es->luastate, -1);
|
||||||
EINA_SAFETY_ON_FALSE_RETURN_VAL(elua_state_require_ref_push(es), -1);
|
EINA_SAFETY_ON_FALSE_RETURN_VAL(elua_state_require_ref_push(es), -1);
|
||||||
lua_pushstring(es->luastate, libname);
|
lua_pushstring(es->luastate, libname);
|
||||||
return elua_report_error(es, es->progname,
|
return elua_error_report(es, es->progname,
|
||||||
lua_pcall(es->luastate, 1, 0, 0));
|
lua_pcall(es->luastate, 1, 0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -462,7 +462,7 @@ elua_util_file_run(Elua_State *es, const char *fname)
|
||||||
{
|
{
|
||||||
EINA_SAFETY_ON_NULL_RETURN_VAL(es, -1);
|
EINA_SAFETY_ON_NULL_RETURN_VAL(es, -1);
|
||||||
EINA_SAFETY_ON_NULL_RETURN_VAL(es->luastate, -1);
|
EINA_SAFETY_ON_NULL_RETURN_VAL(es->luastate, -1);
|
||||||
return elua_report_error(es, es->progname,
|
return elua_error_report(es, es->progname,
|
||||||
elua_io_loadfile(es, fname)
|
elua_io_loadfile(es, fname)
|
||||||
|| _elua_docall(es, 0, 1));
|
|| _elua_docall(es, 0, 1));
|
||||||
}
|
}
|
||||||
|
@ -472,7 +472,7 @@ elua_util_string_run(Elua_State *es, const char *chunk, const char *chname)
|
||||||
{
|
{
|
||||||
EINA_SAFETY_ON_NULL_RETURN_VAL(es, -1);
|
EINA_SAFETY_ON_NULL_RETURN_VAL(es, -1);
|
||||||
EINA_SAFETY_ON_NULL_RETURN_VAL(es->luastate, -1);
|
EINA_SAFETY_ON_NULL_RETURN_VAL(es->luastate, -1);
|
||||||
return elua_report_error(es, es->progname,
|
return elua_error_report(es, es->progname,
|
||||||
luaL_loadbuffer(es->luastate, chunk, strlen(chunk),
|
luaL_loadbuffer(es->luastate, chunk, strlen(chunk),
|
||||||
chname)
|
chname)
|
||||||
|| _elua_docall(es, 0, 0));
|
|| _elua_docall(es, 0, 0));
|
||||||
|
@ -531,5 +531,5 @@ elua_util_script_run(Elua_State *es, int argc, char **argv, int n, int *quit)
|
||||||
*quit = lua_toboolean(es->luastate, -1);
|
*quit = lua_toboolean(es->luastate, -1);
|
||||||
lua_pop(es->luastate, 1);
|
lua_pop(es->luastate, 1);
|
||||||
}
|
}
|
||||||
return elua_report_error(es, es->progname, status);
|
return elua_error_report(es, es->progname, status);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue