深圳专业网站建设多少钱,蜘蛛搜索,百度地图怎么搜街景,珠海网站建设 超凡科技文章目录 1. Lua 调用 C++ DLL 的机制入口与注册entry.luaDLL 导出接口`onSimulationStart`代码`onSimulationFrame`代码`setUnitsData`代码生命周期与回调`onSimulationStart`代码`onSimulationFrame`代码`onSimulationStop`代码`coreInit`代码`coreFrame`代码`coreDeinit`代码…
文章目录
1. Lua 调用 C++ DLL 的机制
入口与注册
entry.lua
DLL 导出接口
`onSimulationStart`代码
`onSimulationFrame`代码
`setUnitsData`代码
生命周期与回调
`onSimulationStart`代码
`onSimulationFrame`代码
`onSimulationStop`代码
`coreInit`代码
`coreFrame`代码
`coreDeinit`代码
2. DLL 与 DCS World 的交互
Lua State 共享
示例
数据交互方式
dcstools.cpp
线程与同步
3. 典型流程举例
4. 总结
1. Lua 调用 C++ DLL 的机制
入口与注册
在 DCS World 的 Mods 目录下,Olympus 以插件形式加载,Lua 脚本(如 entry.lua)声明插件并初始化。
主要 Lua 脚本(如 OlympusCommand.lua)负责加载 DLL,并通过 require("olympus") 或 package.loadlib 方式调用 C++ 导出的 Lua C API。
entry.lua
local self_ID ="DCS-Olympus"declare_plugin(self_ID,{image ="Olympus.png",installed =true,-- if false that will be place holder , or advertisingdirName = current_mod_path,binaries ={-- 'Olympus',},load_immediately =true,displayName ="Olympus",shortName ="Olympus",fileMenuName ="Olympus",version ="{{OLYMPUS_VERSION_NUMBER}}",state ="installed",developerName="DCS Refugees 767 squadron",info =_("DCS Olympus is a mod for DCS World. It allows users to spawn, control, task, group, and remove units from a DCS World server using a real-time map interface, similarly to Real Time Strategy games. The user interface also provides useful informations units, like loadouts, fuel, tasking, and so on. In the future, more features for DCS World GCI and JTAC will be available."),Skins ={{name ="Olympus",dir ="Theme"},},Options ={{name ="Olympus",nameId ="Olympus",dir ="Options",CLSID ="{Olympus-options}"},},})plugin_done()
DLL 导出接口
C++ 侧通过 extern "C" DllExport int luaopen_olympus(lua_State *L) 导出模块初始化函数,供 Lua 加载。