Adolfram Posted November 8, 2020 Share Posted November 8, 2020 Is there a way to get/set environment variables in MTA Lua? I've tried os.getenv but it errors for "unsecure function calling". Link to comment
Moderators IIYAMA Posted November 8, 2020 Moderators Share Posted November 8, 2020 4 minutes ago, Adolfram said: Is there a way to get/set environment variables in MTA Lua? I've tried os.getenv but it errors for "unsecure function calling". Just use the config file. https://wiki.multitheftauto.com/wiki/GetResourceConfig While the syntax might be different, it's goal is exactly the same. Link to comment
Adolfram Posted November 8, 2020 Author Share Posted November 8, 2020 I'm afraid it is not. I've set up a docker environment for my dev/prod servers and the only way I can distinguish dev and prod is the ports. Link to comment
Moderators IIYAMA Posted November 8, 2020 Moderators Share Posted November 8, 2020 1 minute ago, Adolfram said: I'm afraid it is not. I've set up a docker environment for my dev/prod servers and the only way I can distinguish dev and prod is the ports. There is no global Lua environment afaik, atleast not that I am aware of. Each resource has it's own environment. But that doesn't mean a resource can't get information through http. If you want MTA to native support custom Lua env. variables, you probably need to create a module or modify MTA itself. 1 Link to comment
Adolfram Posted November 8, 2020 Author Share Posted November 8, 2020 I don't really see how this would work over http but I'll look into modules. Thanks. 1 Link to comment
4O4 Posted November 12, 2020 Share Posted November 12, 2020 On 08/11/2020 at 13:09, Adolfram said: I'm afraid it is not. I've set up a docker environment for my dev/prod servers and the only way I can distinguish dev and prod is the ports. Actually I've made a simple native server module for exactly this purpose - to pass some configuration or secrets via env variables to the MTA server running in docker container. There is a "getSystemEnvVariable(string variableName)" function there (no "set" counterpart as I didn't need it, but could be implemented easily). Currently I haven't published any releases of .dll / .so but the code is available on Github and you can build it yourself easily: https://github.com/4O4/mta-ml-sysutils Generic building instruction is: run "utils/premake5 gmake && cd Build && make" on linux, and on windows run: "utils/premake5.exe vs2019" and then open Build/*.sln file in visual studio and launch build from there. After a successful build the dll / so will be in Bin/ folder. If you need help with building or want me to publish binaries built by me on github releases, just let me know. This module also includes a second utility function "executeSystemCommand(string systemCommand, function commandFinishedCallback(exitCode, stdout, stderr))" for executing system commands asynchronously in a separate thread, although I ended up not using it very much so I don't know about its stability. Should work but no guarantees, I'm just informing you that it exists in the same module and that's why it is called "sysutils". 2 Link to comment
Adolfram Posted November 28, 2020 Author Share Posted November 28, 2020 On 12/11/2020 at 17:17, 4O4 said: Actually I've made a simple native server module for exactly this purpose - to pass some configuration or secrets via env variables to the MTA server running in docker container. There is a "getSystemEnvVariable(string variableName)" function there (no "set" counterpart as I didn't need it, but could be implemented easily). Currently I haven't published any releases of .dll / .so but the code is available on Github and you can build it yourself easily: https://github.com/4O4/mta-ml-sysutils Generic building instruction is: run "utils/premake5 gmake && cd Build && make" on linux, and on windows run: "utils/premake5.exe vs2019" and then open Build/*.sln file in visual studio and launch build from there. After a successful build the dll / so will be in Bin/ folder. If you need help with building or want me to publish binaries built by me on github releases, just let me know. This module also includes a second utility function "executeSystemCommand(string systemCommand, function commandFinishedCallback(exitCode, stdout, stderr))" for executing system commands asynchronously in a separate thread, although I ended up not using it very much so I don't know about its stability. Should work but no guarantees, I'm just informing you that it exists in the same module and that's why it is called "sysutils". Hey, thanks a lot! This should do. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now