From 67ef9208faaa129a73ac2b6e3bbd7c14d0360a72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Cepl?= Date: Mon, 6 Oct 2025 00:03:38 +0200 Subject: [PATCH 1/2] feat: Add support for Lua 5.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit introduces compatibility with Lua 5.1 by: - Lowering the required Lua version in CMakeLists.txt and the rockspec file. - Adding compatibility functions for 'luaL_setfuncs' and 'luaL_newlib'. - Using 'lua_Number' and 'lua_pushnumber' for compatibility with Lua 5.1. Signed-off-by: Matěj Cepl --- CMakeLists.txt | 2 +- editorconfig-core-scm-1.rockspec | 2 +- editorconfig_lua.c | 34 ++++++++++++++++++++++++++------ 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0bcbd96..1c72a62 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,7 +43,7 @@ set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules") include(GNUInstallDirs) find_package(EditorConfig REQUIRED) -set(Lua_FIND_VERSION 5.2) # minimum Lua version +set(Lua_FIND_VERSION 5.1) # minimum Lua version find_package(Lua REQUIRED) set(CMAKE_C_STANDARD 99) diff --git a/editorconfig-core-scm-1.rockspec b/editorconfig-core-scm-1.rockspec index 220f0a3..e578618 100644 --- a/editorconfig-core-scm-1.rockspec +++ b/editorconfig-core-scm-1.rockspec @@ -20,7 +20,7 @@ provides the same functionality as the Editorconfig C Core library.", license = "BSD", } dependencies = { - "lua >= 5.2", + "lua >= 5.1", } build = { type = "cmake", diff --git a/editorconfig_lua.c b/editorconfig_lua.c index 9aadebf..dcaabf2 100644 --- a/editorconfig_lua.c +++ b/editorconfig_lua.c @@ -6,10 +6,10 @@ * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. + * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE @@ -36,6 +36,28 @@ #error "ECL_VERSION is not defined." #endif +#if LUA_VERSION_NUM < 502 +/* + * Lua 5.1 compatibility functions. + * Adapted from Lua 5.2.x source. + */ +static void +luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup) +{ + luaL_checkstack(L, nup, "too many upvalues"); + for (; l->name; l++) { + int i; + for (i = 0; i < nup; i++) + lua_pushvalue(L, -nup); + lua_pushcclosure(L, l->func, nup); + lua_setfield(L, -(nup + 2), l->name); + } + lua_pop(L, nup); +} + +#define luaL_newlib(L, l) (lua_newtable(L), luaL_setfuncs(L, l, 0)) +#endif + /*** * Lua bindings to the EditorConfig C Core library. * @module editorconfig @@ -94,7 +116,7 @@ lec_parse(lua_State *L) editorconfig_handle eh; int name_value_count; const char *name, *value; - lua_Integer idx = 1; + lua_Number idx = 1; /* Use lua_Number for Lua 5.1 compatibility */ eh = open_ec_handle(L); assert(eh != NULL); @@ -108,7 +130,7 @@ lec_parse(lua_State *L) lua_pushstring(L, name); lua_pushstring(L, value); lua_settable(L, 1); - lua_pushinteger(L, idx); + lua_pushnumber(L, idx); /* Use lua_pushnumber for Lua 5.1 compatibility */ lua_pushstring(L, name); lua_settable(L, 2); idx += 1; @@ -149,4 +171,4 @@ int luaopen_editorconfig (lua_State *L) { luaL_newlib(L, editorconfig_reg); add_version(L); return 1; -} +} \ No newline at end of file From 8278a04eec8f891d26aa95391a8f5b57a27b9c8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Cepl?= Date: Fri, 10 Oct 2025 11:31:17 +0200 Subject: [PATCH 2/2] fix: make package to build even with LuaJIT (not only LUA PUC 5.1) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Matěj Cepl --- editorconfig_lua.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/editorconfig_lua.c b/editorconfig_lua.c index dcaabf2..ea9c666 100644 --- a/editorconfig_lua.c +++ b/editorconfig_lua.c @@ -41,7 +41,7 @@ * Lua 5.1 compatibility functions. * Adapted from Lua 5.2.x source. */ -static void +void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup) { luaL_checkstack(L, nup, "too many upvalues"); @@ -55,14 +55,16 @@ luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup) lua_pop(L, nup); } +#ifndef luaL_newlib #define luaL_newlib(L, l) (lua_newtable(L), luaL_setfuncs(L, l, 0)) #endif +#endif /*** * Lua bindings to the EditorConfig C Core library. * @module editorconfig */ - + /* Receives 3 arguments, two optional */ static editorconfig_handle open_ec_handle(lua_State *L) @@ -171,4 +173,4 @@ int luaopen_editorconfig (lua_State *L) { luaL_newlib(L, editorconfig_reg); add_version(L); return 1; -} \ No newline at end of file +}