Skip to content

Commit

Permalink
Stick to the Lua 5.2 C API
Browse files Browse the repository at this point in the history
Aegisub requires Luajit implementing Lua 5.2, but the code was making a
mixture of Lua 5.1 and Lua 5.2 C API calls which happened to work
because luajit's standards compliance is loose.

Tested with some out of tree patches to make Aegisub work on an
unsupported platform (OpenBSD, official Lua).
  • Loading branch information
guijan committed Dec 20, 2024
1 parent b2d6d98 commit 0d38a14
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 12 deletions.
8 changes: 2 additions & 6 deletions libaegisub/lua/modules/lpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@
#undef lua_objlen
#define lua_objlen lua_rawlen

#undef luaL_register
#define luaL_register(L,n,f) \
{ if ((n) == NULL) luaL_setfuncs(L,f,0); else luaL_newlib(L,f); }

#endif


Expand Down Expand Up @@ -2379,8 +2375,8 @@ int luaopen_lpeg (lua_State *L) {
luaL_newmetatable(L, PATTERN_T);
lua_pushnumber(L, MAXBACK);
lua_setfield(L, LUA_REGISTRYINDEX, MAXSTACKIDX);
luaL_register(L, NULL, metapattreg);
luaL_register(L, "lpeg", pattreg);
luaL_setfuncs(L, metapattreg, 0);
luaL_newlib(L, pattreg);
lua_pushliteral(L, "__index");
lua_pushvalue(L, -2);
lua_settable(L, -4);
Expand Down
3 changes: 1 addition & 2 deletions src/auto4_lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,6 @@ namespace {
stackcheck.check_stack(0);

// make "aegisub" table
lua_pushstring(L, "aegisub");
lua_createtable(L, 0, 13);

set_field<LuaCommand::LuaRegister>(L, "register_macro");
Expand All @@ -487,7 +486,7 @@ namespace {
set_field<lua_set_status_text>(L, "set_status_text");

// store aegisub table to globals
lua_settable(L, LUA_GLOBALSINDEX);
lua_setglobal(L, "aegisub");
stackcheck.check_stack(0);

// load user script
Expand Down
4 changes: 2 additions & 2 deletions src/auto4_lua_assfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ namespace {
std::string get_string_field(lua_State *L, const char *name, const char *line_class)
{
get_field(L, name, line_class, lua_isstring);
std::string ret(lua_tostring(L, -1), lua_strlen(L, -1));
std::string ret = lua_tostring(L, -1);
lua_pop(L, 1);
return ret;
}

agi::Color get_color_field(lua_State *L, const char *name, const char *line_class)
{
get_field(L, name, line_class, lua_isstring);
agi::Color ret(std::string_view(lua_tostring(L, -1), lua_strlen(L, -1)));
agi::Color ret = std::string_view(lua_tostring(L, -1));
lua_pop(L, 1);
return ret;
}
Expand Down
5 changes: 4 additions & 1 deletion subprojects/luabins/src/luabins.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ LUALIB_API int luaopen_luabins(lua_State * L)
/*
* Register module
*/
luaL_register(L, "luabins", R);
lua_newtable(L);
luaL_setfuncs(L, R, 0);
lua_pushvalue(L, -1);
lua_setglobal(L, "mylib");

/*
* Register module information
Expand Down
2 changes: 1 addition & 1 deletion subprojects/luabins/src/save.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ static int save_table(
TODO: Note inelegant downsize from size_t to int.
Handle integer overflow here.
*/
int array_size = luabins_min(total_size, (int)lua_objlen(L, index));
int array_size = luabins_min(total_size, (int)lua_rawlen(L, index));
int hash_size = luabins_max(0, total_size - array_size);

result = lbs_writeTableHeaderAt(sb, header_pos, array_size, hash_size);
Expand Down

0 comments on commit 0d38a14

Please sign in to comment.