How does a LUA file invoke a variable of another LUA file?

Source: Internet
Author: User

Come in learning and Chun of the openresty, the individual to Lua is not very skilled, will inevitably encounter a lot of strange problems, here is a little record of some small problems encountered, for others reference.

Internet search related information, most of the information is just to call Lua require or dofile, and the details of the difference between the life, not to say useless, but did not answer my question-how to implement the variable between LUA files on the openresty server?

First, you have to specify the path to the require, and you need to configure the variable "lua_package_path/topath/" inside the HTTP segment. LUA;; ", notice here that the" Topath "is the absolute path and the back two semicolon";; " Can't save.

The variables are then defined in the Lua file (Config.lua) where the variables need to be defined, such as I want to define a table, which should define "table = {a=1, b=2}". Be careful not to add "local" to the front, otherwise you cannot read it.

The last is to refer to Config.lua's global variables in the logical processing LUA, you need to call require ("config"), load the file in, and then call the member of table, directly "TABLE.A" can access the value of a.

How does a LUA file invoke a variable of another LUA file?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.