Jump to content

Environment Variables


Adolfram

Recommended Posts

  • Moderators
Posted
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.

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

  • Moderators
Posted
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.

 

 

 

  • Like 1

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted
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".

  • Like 2

Signature not found.

  • 3 weeks later...
Posted
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.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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