gyrovague Posted December 27, 2016 Posted December 27, 2016 Is there an example somewhere of how to make a minimal DLL with a C function that can be called from Lua (in avLuaDevice) in a DCS module cockpit? I've read a variety of posts, e.g. https://forums.eagle.ru/showthread.php?t=90368 https://forums.eagle.ru/showthread.php?p=1474382 and various Lua docs. I can load a DLL from a Lua file and call the C function, however I can't seem to make this work within a DCS aircraft mod. I add the DLL to the binaries list inside declare_plugin: binaries = { 'hellolib', }, but it's not clear to me whether this is even trying to load my DLL. I'm also not sure whether explicitly using require or loadlib is needed from the Lua code to open the DLL, since it seems to me that have the entry in the binaries list should cause DCS to open the DLL and make it accessible, besides which I haven't had any success using require or loadlib directly inside DCS Lua files anyway (works fine on standalone Lua files outside of DCS). I've created a DLL (64bit, Lua 5.1 headers etc.) with just the following cpp file, compiled to hellolib.dll: #include "stdafx.h" #include <windows.h> #include <stdio.h> #ifdef __cplusplus extern "C" { #endif // __cplusplus #include "lua.h" // the includes for the 64 bit LUA libray #include "lualib.h" #include "luaconf.h" #include "lauxlib.h" #ifdef __cplusplus } #endif // __cplusplus #define DllExport __declspec( dllexport ) static int l_hello(lua_State *L) { lua_pushnumber(L, 42); /* push result */ return 1; /* number of results */ } static const luaL_Reg Map[] = { {"hello", l_hello }, {NULL, NULL} }; DllExport int luaopen_hellolib( lua_State *L) { luaL_register(L, "MyGlobal", Map); // register the list of function return 1; } Then I place hellolib.dll inside the bin subdirectory of my mod, and add an entry to the binaries list in declare_plugin. None of that results in any errors in DCS.log, so either it is getting ignored or loaded successfully or failing silently. Then, where I want to try to call it inside an avLuaDevice instance, I've tried various things (one at a time) which all failed: r=hello() r=MyGlobal.hello() r=MyGlobal:hello() mylib=require("hellolib") -- tried various paths etc. here too to try to get it to load, to no avail -- mylib=require(current_mod_path.."/bin/hellolib") r=mylib:hello() Any ideas? As a bonus, it would be nice if the DLL could actually also access the APIs defined in the API\include\Cockpit\ccParametersAPI.h file, to be able to exchange param values with the Lua devices. I've been headbutting against this for several hours now, and I don't know whether I have few or many things wrong. Would really appreciate any tips from people that have successfully done this. ( Note: I am not talking about EFM dll here, I can get the ED_FM_Template dll compiled and working with our mod ) ____________ Heatblur Simulations [sIGPIC][/sIGPIC]
tintifaxl Posted December 27, 2016 Posted December 27, 2016 Mixing a managed and an unmanaged programming language. What a nightmare ... Windows 10 64bit, Intel i9-9900@5Ghz, 32 Gig RAM, MSI RTX 3080 TI, 2 TB SSD, 43" 2160p@1440p monitor.
gyrovague Posted December 28, 2016 Author Posted December 28, 2016 Mixing a managed and an unmanaged programming language. What a nightmare ... True, but that is pretty much the Lua claim to fame and why it is used in virtually every game engine for scripting. ____________ Heatblur Simulations [sIGPIC][/sIGPIC]
Raf Posted April 9, 2023 Posted April 9, 2023 Hey did you figure out how to do it properly? I am currently looking in how to make a binary lua module in rust to load it via require in DCS. My module checks out fine in a downloaded 64bit lua 5.1.5 interpreter, but when I run it with the one in dcs folder, it keeps getting 'The specified module could not be found."
PravusJSB Posted May 21, 2023 Posted May 21, 2023 Did you setup a luaopen method for your binary? I also think the binary might need to be named with "lua-" prefix for calling in the mission environment (i think) Creator & Developer of XSAF ::An AI model that wants to kill you, and needs no help from humans. Discord: PravusJSB#9484 twitch.tv/pravusjsb https://www.patreon.com/XSAF https://discord.gg/pC9EBe8vWU https://bmc.link/johnsbeaslu Work with me on Fiverr: https://www.fiverr.com/pravusjsb
Recommended Posts