How do I use print in Atom with love2d - atom-editor

I'm a newbie to love and i'm using Love 11.3 and Sheepolution guide to learning love. In one of their chapters they say
We can use print to make the number appear in our output console.
print(3 + 4). --Output: 7. Run your code (meaning press F6 and then
close the window to show the output) and your console should say 7
My code:
function love.draw()
love.graphics.print("Hello world!", 100,100)
end
print(3+4)
When I run this code, a black screen with "Hello world" comes up but nothing says "7". Even in ATOM, down below has a section "Atom-console" but nothing prints there. Is there something I didn't do in my setup that causes the regular print function not to print?

Love2D captures the console output by default. You need to create a new file, conf.lua in the same folder as main.lua. Your file structure should look like:
MyProject.love
|- main.lua
|- conf.lua
In conf.lua we have to turn on the Love2D console with the following:
function love.conf(t)
t.console = true
end

Related

GNAT GPS: Add a custom command

I would like to know if it is possible to add a custom command to the GNAT Programming Studio (GPS)?
If the custom command is invoked (by a button in the menu bar or a keyboard shortcut) an external Python script should be called with the full/absolute path to the file that is opened and selected in the editor.
This is a quick-and-dirty script that might give some direction. I tested it on Linux, but it should also work on Windows. Change the action near the end to invoke the script you like. To actually use it, you must put it in the (hidden) .gps/plug-ins directory which can be found in your home directory. The actual action can be invoked from the context menu in the source code window.
run_my_script.py
"""Run Python Script
This plug-in executes a python script.
"""
###########################################################################
# No user customization below this line
###########################################################################
import os, sys
import GPS
from gps_utils import interactive
def __contextualMenuFilter(context):
# Check if the context is generated by the source editor
if not (context.module_name == "Source_Editor"):
return False
# If all OK, show the menu item in the context menu.
return True
def __contextualMenuLabel(context):
# Get current buffer
name = context.file().name()
basename = os.path.basename(name)
# Name of the menu item.
return "Run Python script for <b>{}</b>".format(basename)
#interactive(
name ="Run Python script",
contextual = __contextualMenuLabel,
filter = __contextualMenuFilter)
def on_activate():
# If modified, then save before proceeding.
eb = GPS.EditorBuffer.get()
if eb.is_modified:
eb.save()
# Run the action (defined below).
GPS.execute_action("my_script")
GPS.parse_xml ("""
<action name="my_script">
<external output="Output of my_script">python3 /home/deedee/my_script.py %F</external>
</action>""")
my_script.py (some test script)
import sys
print ("Running script {0} for {1}".format(sys.argv[0], sys.argv[1]));
output (shown in GPS on a new tab named "Output of my_script")
python3 /home/deedee/my_script.py /home/deedee/example/src/main.adb
Running script /home/deedee/my_script.py for /home/deedee/example/src/main.adb
Some relevant info from the GNAT Studio (formerly GPS) documentation:
15.5.2. Defining Actions
15.5.3. Macro arguments
15.8.7.3. Redirecting the output of spawned processes
17. Scripting API reference for GPS

AutoIt Scripting for an External CLI Program - eac3to.exe

I am attempting to design a front end GUI for a CLI program by the name of eac3to.exe. The problem as I see it is that this program sends all of it's output to a cmd window. This is giving me no end of trouble because I need to get a lot of this output into a GUI window. This sounds easy enough, but I am begining to wonder whether I have found one of AutoIt's limitations?
I can use the Run() function with a windows internal command such as Dir and then get the output into a variable with the AutoIt StdoutRead() function, but I just can't get the output from an external program such as eac3to.exe - it just doesn't seem to work whatever I do! Just for testing purposesI I don't even need to get the output to a a GUI window: just printing it with ConsoleWrite() is good enough as this proves that I was able to read it into a variable. So at this stage that's all I need to do - get the text (usually about 10 lines) that has been output to a cmd window by my external CLI program into a variable. Once I can do this the rest will be a lot easier. This is what I have been trying, but it never works:
Global $iPID = Run("C:\VIDEO_EDITING\eac3to\eac3to.exe","", #SW_SHOW)
Global $ScreenOutput = StdoutRead($iPID)
ConsoleWrite($ScreenOutput & #CRLF)
After running this script all I get from the consolWrite() is a blank line - not the text data that was output as a result of running eac3to.exe (running eac3to without any arguments just lists a screen of help text relating to all the commandline options), and that's what I am trying to get into a variable so that I can put it to use later in the program.
Before I suggest a solution let me just tell you that Autoit has one
of the best help files out there. Use it.
You are missing $STDOUT_CHILD = Provide a handle to the child's STDOUT stream.
Also, you can't just do RUN and immediately call stdoutRead. At what point did you give the app some time to do anything and actually print something back to the console?
You need to either use ProcessWaitClose and read the stream then or, you should read the stream in a loop. Simplest check would be to set a sleep between RUN and READ and see what happens.
#include <AutoItConstants.au3>
Global $iPID = Run("C:\VIDEO_EDITING\eac3to\eac3to.exe","", #SW_SHOW, $STDOUT_CHILD)
; Wait until the process has closed using the PID returned by Run.
ProcessWaitClose($iPID)
; Read the Stdout stream of the PID returned by Run. This can also be done in a while loop. Look at the example for StderrRead.
; If the proccess doesnt end when finished you need to put this inside of a loop.
Local $ScreenOutput = StdoutRead($iPID)
ConsoleWrite($ScreenOutput & #CRLF)

Run bash command for currently selected line

I'd like to be able to hit a shortcut like cmd-shift-r and have that automatically run a bash command, say, mix test test/turtle/api/v3_test.exs:72.
In other words: mix test {FILE_ACTIVE}:{FILE_ACTIVE_LINE_NUMBER}
What is the best way to accomplish this? Is there an atom package that takes care of this or something I could write quickly myself?
Thanks!
There is a fairly low-fi way to get this to work using your init.coffee load this by going to File → Init Script... or by choosing Application: Open Your Init Script from the Command Palette.
Add the following to the bottom of your init.coffee:
atom.commands.add 'atom-text-editor',
'custom:execute-this-test': ->
if editor = atom.workspace.getActiveTextEditor()
row = editor.getCursors()[0].getBufferRow() + 1
path = editor.buffer.file.path
{spawn} = require 'child_process'
mix = spawn 'mix', ['test', "#{path}:#{row}"]
mix.stderr.on 'data', (data) ->
atom.notifications.addError data.toString()
mix.stdout.on 'data', (data) ->
atom.notifications.addInfo data.toString()
mix.on 'exit', (code) ->
atom.notifications.addInfo "Exited with Code #{code}"
Save the file with Ctrl-S and reload the text editor with Ctrl-Alt-R.
Once Atom has restarted, find the line in the file you want to execute the code against and open the Command Palette with Ctrl-Shift-P and search for Execute This Test.
You may want to tweak the code to be reduce the amount of output it generates, however the above is probably enough to get you started. If you wanted to optimize the workflow even further you can create a Keybinding.

How to run Go(lang) code directly from terminal/command line?

I want to run simple go code directly from terminal/command line. For example:
go run "
package main
func main() {
println("hello")
}
"
hello
However golang allows code execution only from file. So maybe there are some ways how to emulate it? Like this:
go run file.go < echo "...."
But there should be no files after actions above.
In command-line, only a project like go-repl would compile/run a multi-line go source code without leaving any .go file behind.
An alternative: gore:
$ gore
Enter one or more lines and hit ctrl-D
func test() string {return "hello"}
println(test())
^D
---------------------------------
hello
(Other repl-like solution are listed in "Does Go provide REPL?")
Or you would need to develop a go wrapper which would internally create a source code and go run it, before deleting it.
Ubuntu has a gorun tool which works well for small scripts. It compiles scripts on the fly, caching the binaries in /tmp.
https://wiki.ubuntu.com/gorun
Although it's intended for scripting and not as a REPL, you could use it in various ways.
Although gorun has come from the Ubuntu community, it should work on any Linux distro because it uses vanilla Go source code via
$ go get launchpad.net/gorun

R: I fail to pause my code

I am trying to pause my code for a little while, time for me to observe the plots.
I tried:
print('A')
something = readline("Press Enter")
print('B')
print('C')
, then there is no pause, the line print('B') is fed to readline and get stored into something and therefore only A and C got printed on the screen. Note that if I add an empty line between Something = readline("Press Enter") and print("B"), then print("B") get printed on the screen but still the console doesn't allow the user to press enter before continuing.
And I tried:
print('A')
Sys.sleep(3)
print('B')
print('C')
The program waits 3 seconds before starting and then run "normally" without doing any pause between print('A') and print('B').
What do I missunderstand?
Here is my R version: R 3.1.1 GUI 1.65 Snow Leopard build (6784)
The problem with readline is that if you paste your script into an R console, or execute it from eg Rstudio, the redline function is read and then the next line of the script is read in as the console entry, which in your case sets the value of something to print('B).
An easy way to get around this is to stick your entire code in a function, then call the function to run it. So, in your case:
myscript = function(){
print('A')
something = readline(prompt = "Press Enter")
print('B')
print('C')
}
myscript()
The output of this for me (in Rstudio, with R version 3.1.1):
[1] "A"
Press Enter
[1] "B"
[1] "C"
This has always felt like a bit of a hack to me, but it's essentially what the readline documentation recommends in its example.
I've never used sleep in my code, so I can't help you there.
Edit to clarify based on comments: This will only work if myscript() is the very last line of your script, or if it is manually entered into the console after running the script to generate the function. Otherwise, you will run into the same problem as before- the next line of code will be automatically entered.

Resources