问题
How do you execute a lua file in sublime text 3? I tried opening the console and typing build <filename>.lua
. I also looked through the menu's for a build and run. Supposedly saving a file or hitting F7 is supposed to execute lua scripts, but that did not work either. I expected 'helo world' to print in the console upon save and all it said was the file was written.
contents of helo.lua:
print('helo world');
回答1:
You can manually create a build configuration for Lua. However, I suggest that it is simpler to install a Lua package that includes one.
- Install Package Control
- Open the Command Palette (Ctrl-Shift-P on Windows or COMMAND + SHIFT + P on Mac)
- Type something like "packins" to get the "Package Control: Install Package" item.
- After a momentary pause a list of available packages will appear. Type "Lua" to filter to Lua packages.
- My personal favorite is "Lua Dev". Select this package and Package Control will download and install the package for you.
- From now on, if your have your syntax set to Lua for a file (Ctrl-Shift-P, "Set Syntax: Lua", or click in the bottom right corner of the window and choose Lua) then pressing F7 (aka Tools->Build) will evaluate the file using the Lua interpreter.
You may also need to install "Fix Mac Path". At the time of this writing this package was not found by Package Control. Alternatively, install "Fix Mac Path" by running the following command in terminal:
git clone https://github.com/int3h/SublimeFixMacPath.git ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/FixMacPath
回答2:
Go to Tools > Build System > New Build System.
Paste this code
{
"cmd": ["lua", "$file"],
"file_regex": "^lua: (...*?):([0-9]*):?([0-9]*)",
"selector": "source.lua"
}
Save it as lua.sublime-build
To run a lua program press ctrl+B.
PS: Ensure that lua executable is in you $PATH
来源:https://stackoverflow.com/questions/28237929/how-do-you-execute-a-lua-file-in-sublime-text-3