fix(build): distinguish vim.mpack from global require'mpack'

problem: the api of vim.mpack is not compatible with a system provided mpack
solution: don't require 'mpack' directly from the system path
This commit is contained in:
bfredl 2023-04-20 14:41:47 +02:00
parent dbcd1985d1
commit ffaf74f147
9 changed files with 20 additions and 11 deletions

View File

@ -1,4 +1,4 @@
local mpack = require('mpack')
local mpack = vim.mpack
if arg[1] == '--help' then
print('Usage: lua genvimvim.lua src/nvim runtime/syntax/vim/generated.vim')

View File

@ -1171,9 +1171,6 @@ static const luaL_reg mpack_functions[] = {
{NULL, NULL}
};
#ifdef NLUA_WIN32
__declspec(dllexport)
#endif
int luaopen_mpack(lua_State *L)
{
/* Unpacker */

View File

@ -1,6 +1,3 @@
#include <lua.h>
#ifdef NLUA_WIN32
__declspec(dllexport)
#endif
int luaopen_mpack(lua_State *L);

13
src/nlua0.c Normal file
View File

@ -0,0 +1,13 @@
#include <lua.h>
#include "mpack/lmpack.h"
LUA_API int luaopen_nlua0(lua_State* L);
LUA_API int luaopen_nlua0(lua_State* L) {
lua_getglobal(L, "vim");
luaopen_mpack(L);
lua_setfield(L, -2, "mpack");
return 1;
}

View File

@ -15,7 +15,7 @@ endif()
add_library(nlua0 MODULE)
if(WIN32)
target_compile_definitions(nlua0 PUBLIC LUA_BUILD_AS_DLL NLUA_WIN32)
target_compile_definitions(nlua0 PUBLIC LUA_BUILD_AS_DLL LUA_LIB)
set_target_properties(nlua0 PROPERTIES ENABLE_EXPORTS TRUE)
elseif(APPLE)
set_target_properties(nlua0 PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
@ -322,6 +322,7 @@ if(PREFER_LUA)
target_compile_definitions(main_lib INTERFACE NVIM_VENDOR_BIT)
endif()
list(APPEND NLUA0_SOURCES ${PROJECT_SOURCE_DIR}/src/nlua0.c)
foreach(subdir
os
api

View File

@ -1,4 +1,4 @@
local mpack = require('mpack')
local mpack = vim.mpack
local hashy = require'generators.hashy'

View File

@ -1,4 +1,4 @@
local mpack = require('mpack')
local mpack = vim.mpack
assert(#arg == 5)
local input = io.open(arg[1], 'rb')

View File

@ -1,4 +1,4 @@
local mpack = require('mpack')
local mpack = vim.mpack
local autodir = arg[1]
local metadata_file = arg[2]

View File

@ -4,6 +4,7 @@ package.path = srcdir .. '/src/nvim/?.lua;' ..srcdir .. '/runtime/lua/?.lua;' ..
_G.vim = require'vim.shared'
_G.vim.inspect = require 'vim.inspect'
package.cpath = package.cpath .. ';' .. nlualib
require 'nlua0'
arg[0] = table.remove(arg, 1)
return loadfile(arg[0])()