refactor(gen_api_dispatch): avoid trailing spaces (#32632)

Problem:
Generated Lua API bindings may have trailing spaces (e.g. nvim_set_hl).

Solution:
Add leading spaces only if arg_free_code is non-empty.
Also:
- Remove an unnecessary string.format() in write_shifted_output() args.
- Fix incorrect indent for the nlua_push_keydict() below.
This commit is contained in:
zeertzjq
2025-02-26 20:23:27 +08:00
committed by GitHub
parent c619d1da61
commit 85caaa70d4

View File

@@ -901,7 +901,7 @@ exit_0:
local ret_mode = (ret_type == 'Object') and '&' or ''
if fn.has_lua_imp then
-- only push onto the Lua stack if we haven't already
write_shifted_output(string.format(
write_shifted_output(
[[
if (lua_gettop(lstate) == 0) {
nlua_push_%s(lstate, %sret, kNluaPushSpecial | kNluaPushFreeRefs);
@@ -909,7 +909,7 @@ exit_0:
]],
return_type,
ret_mode
))
)
elseif string.match(ret_type, '^KeyDict_') then
write_shifted_output(
' nlua_push_keydict(lstate, &ret, %s_table);\n',
@@ -927,7 +927,6 @@ exit_0:
-- NOTE: we currently assume err_throw needs nothing from arena
write_shifted_output(
[[
%s
%s