简体   繁体   中英

how to pass a run time variables to python script from inside lua?

I hava a code in lua produce images and other data containers then these data should be used in another python script.

i tried to use (os.execute(command)) as it shown here https://www.lua.org/pil/22.2.html but i don't know how to pass these parameters direct from lua to python scriprt as arguments

Command-line arguments can only be strings—and only relatively short strings, and only strings which can be handled by your default system encoding.

If you need to pass data that's large, or structured, or just arbitrary binary bytes, you can't use command-line arguments.

The simplest solution is to save the data in a file, then pass the filename as a command-line argument. Then, on the Python side, you just open and read the same file.

You can also stream data into the child process's standard input. Lua doesn't come with anything like Python's subprocess module, but sometimes popen is sufficient.

When popen isn't sufficient, you can build it yourself atop POSIX or Windows API calls. See this answer for an example of doing it for POSIX.

You can also just open a pipe, shared memory segment, etc. for the child to inherit, and then pass a file descriptor or key as a command-line argument.

Finally, you can write a simple socket server (possibly using a higher-level protocol that libraries already exist for ranging from Netstrings over UDP up to HTTP) and pass the port number as a command-line argument.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM