r/lua • u/ChemODun • Mar 25 '25
Help How write a right annotation/definition for X4: Extensions Lua functions (exported to Lua from C) for Lua Language Server.
There is a game X4: Extensions with is use the Lua for some scenarios. And it given a possibility to use Lua in modding.
And there is a question: Engine is providing possibility to use some C functions. In the Lua code from original game, it looks like:
local ffi = require("ffi")
local C = ffi.C
ffi.cdef[[
void AddTradeWare(UniverseID containerid, const char* wareid);
]]I tried to make an annotation file for it like
C = {}
-- FFI Function: void AddTradeWare(UniverseID containerid, const char* wareid);
---@param containerid UniverseID
---@param wareid const char*
function C.AddTradeWare(containerid, wareid) endBut Language Server not shown this information in tooltip and stated it as unknown. (field) C.AddTradeWare: unknown
Is there any possibility to make it work?
P.S. With other functions, "directly" accessible, i.e. without this local ffi, local C everything is working fine
2
u/weregod Mar 25 '25
Are you sure that annotation file is loaded? ffi is standard LuaJIT module maybe LSP loads standard definition instead of your custom one.
2
u/IllustrisJack Mar 25 '25 edited Mar 25 '25
The language server won´t know that
when defining new annotations.
Should be
i guess you could also do:
wherever you use it after you defined the class earlier?
or you can use meta files which for example we did for our rust lua ffi generator:
https://github.com/Limit-Theory-Redux/ltheory/tree/main/engine/lib/phx/script/meta
see https://luals.github.io/wiki/annotations/#meta
conceptually: