- luainstance: allow access to defined directories

Signed-off-by: Thilo Graf <dbt@novatux.de>
This commit is contained in:
svenhoefer
2021-09-23 22:57:25 +02:00
committed by Thilo Graf
parent ce09b670c5
commit e904e2191f
3 changed files with 67 additions and 1 deletions

View File

@@ -4,4 +4,4 @@
* to luainstance.h changes
*/
#define LUA_API_VERSION_MAJOR 1
#define LUA_API_VERSION_MINOR 92
#define LUA_API_VERSION_MINOR 93

View File

@@ -414,6 +414,42 @@ static void set_lua_variables(lua_State *L)
{ NULL, 0 }
};
/* directories, exported as e.g. DIR['CONFIGDIR'] */
table_key_s directories[] =
{
{ "CONFIGDIR", CONFIGDIR },
{ "DATADIR", DATADIR },
{ "DATADIR_VAR", DATADIR_VAR },
{ "CONTROLDIR", CONTROLDIR },
{ "CONTROLDIR_VAR", CONTROLDIR_VAR },
{ "FONTDIR", FONTDIR },
{ "FONTDIR_VAR", FONTDIR_VAR },
{ "LIBDIR", LIBDIR },
{ "GAMESDIR", GAMESDIR },
{ "ICONSDIR", ICONSDIR },
{ "ICONSDIR_VAR", ICONSDIR_VAR },
{ "LOCALEDIR", LOCALEDIR },
{ "LOCALEDIR_VAR", LOCALEDIR_VAR },
{ "PLUGINDIR", PLUGINDIR },
{ "PLUGINDIR_MNT", PLUGINDIR_MNT },
{ "PLUGINDIR_VAR", PLUGINDIR_VAR },
{ "LUAPLUGINDIR", LUAPLUGINDIR },
{ "LUAPLUGINDIR_VAR", LUAPLUGINDIR_VAR },
{ "THEMESDIR", THEMESDIR },
{ "THEMESDIR_VAR", THEMESDIR_VAR },
{ "WEBRADIODIR", WEBRADIODIR },
{ "WEBRADIODIR_VAR", WEBRADIODIR_VAR },
{ "WEBTVDIR", WEBTVDIR },
{ "WEBTVDIR_VAR", WEBTVDIR_VAR },
{ "LOGODIR", LOGODIR },
{ "LOGODIR_VAR", LOGODIR_VAR },
{ "PRIVATE_HTTPDDIR", PRIVATE_HTTPDDIR },
{ "PUBLIC_HTTPDDIR", PUBLIC_HTTPDDIR },
{ "HOSTED_HTTPDDIR", HOSTED_HTTPDDIR },
{ "FLAGDIR", FLAGDIR },
{ NULL, 0 }
};
/* list of environment variable arrays to be exported */
lua_envexport e[] =
{
@@ -467,6 +503,26 @@ static void set_lua_variables(lua_State *L)
lua_setglobal(L, e_u[i].name);
i++;
}
lua_envexport_s e_s[] =
{
{ "DIR", directories },
{ NULL, NULL }
};
i = 0;
while (e_s[i].name) {
int j = 0;
lua_newtable(L);
while (e_s[i].t[j].name) {
lua_pushstring(L, e_s[i].t[j].name);
lua_pushstring(L, e_s[i].t[j].code);
lua_settable(L, -3);
j++;
}
lua_setglobal(L, e_s[i].name);
i++;
}
}
const char CLuaInstance::className[] = LUA_CLASSNAME;

View File

@@ -91,6 +91,11 @@ struct table_key_u {
lua_Unsigned code;
};
struct table_key_s {
const char *name;
const char *code;
};
struct lua_envexport {
const char *name;
table_key *t;
@@ -101,6 +106,11 @@ struct lua_envexport_u {
table_key_u *t;
};
struct lua_envexport_s {
const char *name;
table_key_s *t;
};
/* this is stored as userdata in the lua_State */
struct CLuaData
{