Skip to content

Commit

Permalink
Add lutro.featureflags table, for use in determining lutro build capa…
Browse files Browse the repository at this point in the history
…bilities (#266)

This is primarily intended for use in internal dev and unit test development. A practical application is that it can be used (soon) to detect whether the lutro build supports the transform rendering feature, and then alter lua graphics test behavior accordingly.

Co-authored-by: nstbayless <[email protected]>
  • Loading branch information
jstine35 and nstbayless authored Jan 25, 2025
1 parent c0db853 commit 1051fcc
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
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(void)
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

0 comments on commit 1051fcc

Please sign in to comment.