Running a lua program from a text file - lua

I've just started learning Lua, and I'm trying to get the native Lua interpreter to run a program that has been saved to a .txt file. I'm running Windows Vista with Lua 5.1.4.
Perhaps I'm missing something, but the only thing my book (Programming in Lua) says is that all you have to do to run your program is to call the interpreter with the name of the text file that contains your program. Then it gives this supposedly handy piece of code:
% lua filename.lua
Which I can't get to work in cmd or in the Lua interpreter. Further research I've done indicates that I might need to use a
dofile("filename.lua")
command, but I'm not sure how to do this. Specifically, what information do I need to put in the argument? Any help you can give is greatly appreciated.

You need to download a Win32 binary (see lua-5.2.1_Win32_bin.zip or lua-5.2.1_Win64_bin.zip here). Unzip this somewhere. How to run your script, in order of easiness and inverse order or common procedure:
Drag your script onto the Lua.exe using the Windows file Explorer.
a. Move your script to the same folder as Lua.exe
b. Shift right-click on that folder and select Open Command Window Here.
c. Type lua filename.lua and press Enter.
Add the directory containing Lua.exe to your system PATH, then do steps 2a and 2b on the folder containing your script.
Integrate Lua.exe with your editor in some way (how you do this depends on your editor).

Related

How to create a program that runs my LUA code?

So, hi!
I am very new to Coding outside of a Game-Creation Program that automatically creates executable files for me, and from Create Your Frisk and other projects, I know a decent chunk of the basics in LUA. but how do I make a program out of it?
Like, How do I make an executable?(I'm using visual studio to code)
You need a Lua interpreter that runs your Lua code.
Either you use a standalone Lua interpreter, a little executable that can only run Lua scripts, or you embedd a Lua interpreter into your own application.
See http://www.lua.org/start.html

How to install Lua GUI in ZBS IDE

I am completely new to programming in Lua outside a sandbox.
I have found a library called Lua GUI that I'd like to use (https://github.com/williamwilling/luagui/). I have still not understood how to quite install the library, and how I even go about using it.
That's part 1 of my question; How can I install Lua GUI(or an library for that matter), and then how do I go about actually using it? By that I mean, is it as simple as writing a program that starts with "require "gui"" and then running it, or is there more to it?
Part 2 of my question is then how do I go about installing it as a package for ZeroBrane Studio IDE, I have no idea at all what the readme file is instructing me to do so I would be grateful if someone could clarify.
If you copy the contents of the src folder in the luagui project to your project directory you should be able to call:
local gui = require("gui")
in your main Lua file and use it that way.

Lua obfuscator, how to

I understand this question will appear silly but I'm clueless what to do, which makes it even more silly. I have written a lua script for a game - which works, but I've never actually run any lua with the lua programs(from the site download). I would like to obfuscate my lua code with this tool: https://github.com/mlnlover11/XFuscator but I'm unsure how to do it, I tried running the lua program and browsing there, dropping the xfuscator file on top of the program etc but nothing has given any result.How should I do it?
Open a command line (e.g. under windows, that's cmd). Go into the directory where you have your local copy of XFuscator. Make sure lua is on your PATH. Type
lua XFuscator.lua -h
This should show the help message, which will describe the next steps.

Lua Debugger that can Attach to Process

My company has a program that uses Lua embedded in its runtime, loading up .lua files from disk and executing functions defined in them repeatedly.
Is there a way to attach to the running process and set breakpoints in my .lua files? (I'd accept either gdb-style command-line debugging as part of the Lua distribution, or perhaps a third-party IDE that provides Visual-Studio-like GUI breakpoints.)
Or is what I'm asking for entirely nonsensical and impossible given the nature of the runtime loading up random files from disk?
Edit: Looks like it's not nonsensical, given that Lua's own debug.getinfo() function can determine the source file for a given function, and debug.sethook() allows a callback for each new line of code entered. So, it's reasonable to load source code from disk and be able to tell when the interpreter is executing a particular line of code from that file. The question remains: how do I latch onto an existing process that has a Lua interpreter and inject my own trace function (which can then watch for file/line number pairs and pause execution)?
If you can modify the .lua files, you can insert the following call just before anything you need to debug:
require 'remdebug.engine'.start()
It starts the RemDebug Lua debugger engine and tries to connect to a controller. If it cannot connect, it will just continue running as normal. I did some fixes to the debugger engine, such as dealing with temporary variables, and my student is working on a debugger GUI (due next year).
In the meantime, you can try if Lua Development Tools works for you. It features a debugger similar to RemDebug, which should be possible to set up as follows:
require("debugger")(host, port, idekey)
Alternatively, you can use SciTE-debug, which is an extension to the SciTE editor, and can serve as a controller to RemDebug. Just make sure you insert the call to remdebug.engine.start somewhere in your Lua code and insert this into the SciTE output window:
:debug.target=remote.lua
When you start your program, SciTE should show the source and current line.
I've been using Decoda editor for that. It allows you to attach to a running C++ application, after that it detects that you're running a Lua Interpreter within your C++ code and show your Lua source code, where you can add beakpoints and inspect variables as usual.
This is an alternative I use after much searching. If you have an external executable that loads lua, I got this working in a few minutes. The op is very responsive, it has an interactive debugger which loads your code you can place debug points interactively. It doesn't have an editor, but I use scite or crimson editor and start the executable, one line in your main lua module enables the debugger.
http://www.cushy-code.com/grld/ - this link seems dead now
I've moved to eclipse.org/ldt it has an ide and integrated debugger, recommended
hth
The Lua plugin for IntelliJ has a working debugger with no special setup required other than pointing to your Lua interpreter.
Here's a screencast of it:
http://www.screencast.com/t/CBWIkoZPg
Similar to what Michal Kottman described, I have implemented a debugger based on RemDebug, but with additional fixes and features (on github: https://github.com/pkulchenko/MobDebug).
You can update your .lua file with require("mobdebug").start("localhost", 8171) at the point where you want the debugging to start. You can then use the command line debugger to execute commands, set breakpoints, evaluate/execute expressions and so on.
As an alternative, you can use ZeroBrane Studio IDE, which integrates with the debugger and gives you a front-end to load your code and execute same debugger commands in a nice GUI. If you want to see the IDE in action, I have a simple demo here: http://notebook.kulchenko.com/zerobrane/live-coding-in-lua-bret-victor-style.
You should probably use Decoda.
Go to Debug -> Processes -> Attach to attach your process. This should work fine.
Well the easiest way is this, thanks to the genius author
https://github.com/slembcke/debugger.lua
you don't need to setup a remote debug server ,just require one file,and simplely call dbg() and it will pause,just like gdb
an tutorial is also shipped with it, check it out.

F# Interactive Developement DirectoryNotFoundException: Could not find a part of the path 'C:\Users\Bob\AppData\Local\Temp\MyFolder\'

When using F# interactive apparently this line of code will search in the path shown in the subject line.
let files = Directory.GetFiles("MyFolderPath")
Is there any way to set interactive to search the same folder the current fsx file is running from? Or any way to control this behavior at all? I'm used to the search starting in bin\Debug obviously and this behavior is throwing me off.
Thanks in advance,
Bob
It depends from where the process fsi.exe is started. Fsi is separated from the IDE, it doesn't know which file is open. When you run Visual Studio, the current directory for fsi is the temp folder.
If you run the fsx file (fsi foo.fsx or right-click "Run with F# Interactive"), fsi will run from current directory.
To see where you are (in which directory), you can do:
Directory.GetCurrentDirectory()
To change directory, use this command:
Directory.SetCurrentDirectory(...)
F# interactive is completely independent of the current F# program (in fact, think of it as running in a separate CMD shell). So I'm afraid, there won't be a simple way to get the currently opened .fsx file.
You might be able to pull something from fsi.CommandLineArgs but I have no VS at hand to confirm this.

Resources