Jump to content

problem with require(“socket”)


Recommended Posts

Posted (edited)

Hi everyone,

 

I’ve searched far and wide on the internet and everywhere in this forums for my problem and I’m hoping I’m doing something obviously wrong since I haven’t seen any discussion close to my problem. And I’m banging my head against the wall trying everything, I have too much patience.

 

I’m trying to use LuaExport in a mission script to get DCS to communicate with a Discord BOT (I’m recreating something I’ve seen out there so I know it’s possible and I’ve tried using the code already available for it on Github so I’m not reinventing the wheel) but I’m throwing an error early in the scripting LUA file that the mission loads.

 

I’m getting the error: attempt to call global “require” (a nil value) when it reads the line: socket = require(“socket”). And yes, I’m including the path for the LuaExport directory prior to the require line, I’m using the example code export.lua file (which is the same as the code from github). It’s as if DCS doesn’t understand the function “require”, I’ve tried so many variations with trial and error it keeps giving me that error. Can anyone with a stronger knowledge of lua explain to me what it means to get this error with DCS?

 

Does something have to be modified/loaded to get DCS to use the require function? Or maybe require is working properly and it’s some other reason that socket is coming back nil.

 

Thanks in advance!

 

Edit- gotta love how I spend a week working on this, banging my head against a wall, finally post, and an hour later figure it out. For any dummies like me out there that run into this, perhaps this will help you as I found nothing in my searches that led to this. But the issue was related to missionscripting.lua. I knew of this file being edited for outputting info (alexra LSO mod for example- if you wanted to export LSO grades) but didn’t realize I needed to do something with this. I actually don’t know what actually did it because I did a few things. 1) I added require “socket” and require “strings”, and 2) I commented out the LIB=nil line. Think it was the LIB = nil that did it but who knows.

 

Or Mods, feel free to delete this post if you find it appropriate to do so.

 

Thanks.

Edited by Sickdog

TM Warthog, TPR, TM MFDs, Pimax Crystal, AMD Ryzen 9 7950X3D. ASUS ROG Crossair X670E Hero AMD X670, G Skill Trident Z5 DDR5 64GB

Posted

The modules are sanitised in the core game directory in missionscripting.lua first, anything subsequent like a mission wont be able to call it. This is why require=nil early on broke every subsequent attempt at adding lua modules. I'm not sure all modules are as simply added, you have more luck with the server API and it's got broader scope.

___________________________________________________________________________

SIMPLE SCENERY SAVING * SIMPLE GROUP SAVING * SIMPLE STATIC SAVING *

Posted (edited)
The modules are sanitised in the core game directory in missionscripting.lua first, anything subsequent like a mission wont be able to call it. This is why require=nil early on broke every subsequent attempt at adding lua modules. I'm not sure all modules are as simply added, you have more luck with the server API and it's got broader scope.

 

Witchcraft tool does something similar, maybe looking at that tool will help.

NOTE: There is a also a problem with the tool install (a fix is discussed HERE)

 

Witchcraft is an interactive debugger that allows debugging your DCS LUA code in web browser and it has a way to get around the sanitisation using a bypass(as discussed in its install docs)

 

(see https://github.com/jboecker/dcs-witchcraft/blob/master/README.md) for details

This may be a work around for your problem by bypassing sanitisation {see Initial Setup and Preparing the Mission sections}

 

 

Do note however the following comments from "MissionScripting.lua"

 

--Sanitize Mission Scripting environment

--This makes unavailable some unsecure functions.

--Mission downloaded from server to client may contain potentialy harmful lua code that may use these functions.

--You can remove the code below and make availble these functions at your own risk.

Edited by Stix_09
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...