Lua loads variables when the program is called ~ Parameter?

I recently got into Computer Craft (Mod for Minecraft), you can encode computers using lua.

I want to go “water status” and it will load “water” and then set the variable to “status” or any other word / line in its place so that I can use it for anything. Perhaps you would call this parameter?

os.run( environment, prgmpath, arguments ) 

I don’t understand what the environment is. prgmpath is water and argument will be status? I just don't know how to extract these arguments from this.

So yes, I am very confused = /

Tried to explain it best, thanks, thanks, Jazza

After searching, I think I found my answer.

 lua water arg1 

Running on command line

 derp = arg[2] 

Included in the file?

EDIT: After I hid a little more, I found out that:

 derp = ... print(derp) 

In the file and:

 file hi 

Hello is printed, so I think it works, but I can no longer add D =

+4
source share
1 answer

os.run is an extension of the os library written specifically for this mod. according to wiki documentation:

  • environment is a metathema for setting state for the script that you use in prgmpath
  • arguments are what you want to pass to the code you are calling located in the script on prgmpath

so basically, if you had some code configured to execute something specific in path / to / file.lua, but it depended on some external state, you would set that state in your calling file and pass the environment (or a subset of it) with the code in the .lua file, passing it as a table to the first parameter in os.run ().

the arguments should be the table of arguments that you wanted to pass to the function that you called in the .lua file. so if in the .lua file you have ...

 function doSomething(arg1, arg2, arg3) ... end 

you will pass arg1, arg2 and arg3 to do something by creating a table and passing it like this:

 local args = {"arg1Val", {}, 1234} os.run({}, '/path/to/file.lua', args) 

os.run will then create an empty environment for the doSomething () function in the .lua file and pass 3 values ​​in the function arguments.

has the meaning?

+1
source

Source: https://habr.com/ru/post/1412245/


All Articles