Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lutro.featureflags table, for use in determining lutro build capabilities #266

Merged
merged 1 commit into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions lutro.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,41 @@ static void init_lutro_global_table(lua_State *L)
lua_pop(L, 1);
}

// reveals which configuration options were used to compile lutro.
static void init_config(lua_State *L)
{
player_checked_stack_begin(L);

luax_reqglobal(L, "lutro");
lua_newtable(L);

char buf[128];

#define STR(a) #a
#define CAPABILITY(cap) \
snprintf(buf, sizeof(buf), "%s", #cap); \
lua_pushboolean(L, (buf[0] && strtold(buf, NULL) != 0)); \
lua_setfield(L, -2, #cap)

CAPABILITY(HAVE_COMPOSITION);
CAPABILITY(HAVE_TRANSFORM);
CAPABILITY(HAVE_INOTIFY);
CAPABILITY(HAVE_JIT);
CAPABILITY(HAVE_LUASOCKET);

#undef STR
#undef CAPABILITY

lua_setfield(L, -2, "featureflags");
lua_pop(L, 1);

(void)player_checked_stack_end(L,0);
}

static int lutro_core_preload(lua_State *L)
{
init_config(L);

return 1;
}

Expand All @@ -229,11 +261,13 @@ static void init_settings(lua_State *L)

void lutro_newlib_x(lua_State* L, luaL_Reg const* funcs, char const* fieldname, int numfuncs)
{
player_checked_stack_begin(L);
luax_reqglobal(L, "lutro");
lua_createtable(L, 0, numfuncs);
luaL_setfuncs(L, funcs, 0);
lua_setfield(L, -2, fieldname);
lua_pop(L, 1);
player_checked_stack_end(L,0);
}

void lutro_init()
Expand Down
1 change: 1 addition & 0 deletions test/main.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
-- Lutro Tester
local availableStates = {
"config/print",
"graphics/print",
"unit/tests",
"joystick/isDown",
Expand Down
2 changes: 1 addition & 1 deletion test/unit/modules/filesystem.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function lutro.filesystem.getUserDirectoryTest()
-- Other aspects of UserDirectory are platform specific and non-trivial to calculate and there
-- isn't much value to trying to replicate it here.
local userDir = lutro.filesystem.getUserDirectory()
local userDirFixed = getUserDir
local userDirFixed = userDir
if userDirFixed:sub(-1) ~= '/' then
userDirFixed = userDirFixed .. '/'
end
Expand Down
1 change: 1 addition & 0 deletions test/unit/tests.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ unit = require 'luaunit'
-- Runs all tests.
function runTests()
local moduleTests = {
require 'modules/featureflags',
require 'modules/filesystem',
require 'modules/graphics',
require 'modules/keyboard',
Expand Down
Loading