Komodo IDE running a Ruby - ruby

I am running a ruby script in Komodo IDE 12.0 . It is a very simple script and I am getting the following error.
c:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/byebug-11.1.3/lib/byebug/setting.rb:12: warning: already initialized constant Byebug::Setting::DEFAULT
c:/ruby27-x64/lib/ruby/gems/2.7.0/gems/byebug-11.1.3/lib/byebug/setting.rb:12: warning: previous definition of DEFAULT was here
wrong number of arguments (given 2, expected 1)
Press any key to continue . . .
the script contains on 1 line and it as follows:
puts "Hello World"

Related

Cannot write files from Lua in Scite on Windows 10?

Using Scite 4.1.3 on Windows 10.
I tried the following Lua script:
function TestFile()
mycontent = "Hello World"
mytmpfilename = os.tmpname()
os.execute("echo aaaa > " .. mytmpfilename) -- create file explicitly;
mytmpfile = io.popen(mytmpfilename, "w") -- w+ crashes Scite in Windows!
mytmpfile:write(mycontent)
mytmpfile:close()
print("readall " .. mytmpfilename .. ": " .. io.popen(mytmpfilename, "r"):read("*a"))
end
If I run this, I get printed:
readall C:\Users\ME\AppData\Local\Temp\s8qk.m:
... which means Lua could not even read this file?! And also, this stupid Windows Explorer prompt shows up:
At end, the content of the C:\Users\ME\AppData\Local\Temp\s8qk.m is still just aaaa.
So obviously, mytmpfile:write part fails silently, and nothing new is written in the file - the only thing that wrote to the file is the echo aaaa > ... executed by cmd.exe via os.execute.
So my question is - how can I write a file with Lua in Scite on Windows? Preferably, without having that stupid "How do you want to open this file?" prompt show up?
Eh, I think I got it ...
See, the OP example uses io.popen - and, if we look at https://man7.org/linux/man-pages/man3/popen.3.html it says:
popen, pclose - pipe stream to or from a process
(emphasis mine).
So, basically, if under Windows I try to do io.popen(filename), then apparently tries to find the process that would be the default "opener" for that file type ... and also therefore the prompt I'm being shown in the OP (and therefore, I could never read or write the files accessed -- or rather, not accessed -- in that way).
However, Programming in Lua : 21.2 – The Complete I/O Model actually uses io.open (notice, no p for process); and then the files seem to open for read/write fine.
So, corrected example from OP should be:
function TestFile()
mycontent = "Hello World"
mytmpfilename = os.tmpname()
-- os.execute("echo aaaa > " .. mytmpfilename) -- create file explicitly; -- no need anymore, with io.open
mytmpfile = io.open(mytmpfilename, "w+") -- w+ crashes Scite in Windows, but only if using io.popen; is fine with io.open!
mytmpfile:write(mycontent)
mytmpfile:close()
print("readall " .. mytmpfilename .. ": " .. io.open(mytmpfilename, "r"):read("*a"))
end

This program does not work from terminal but works in zerobrane

x = 10
io.write("Enter the name of the variable you want to be printed: ")
index = io.read()
f = loadstring("return " .. index)
print(f())
The above code gives this error when used in a terminal, but not when ran in zerobrane studio
main.lua:874: attempt to call a nil value (global 'loadstring')
stack traceback:
main.lua:874: in main chunk [C]: in ?
This is important because i am coding lua in emacs.
how can i correct this problem? Need help.
Your terminal version of Lua is higher than Lua in ZeroBrane.
Lua 5.3 removed loadstring and it exists as load now.

ruby -rdebug doesn't stop at breakpoints

# myapp.rb
myvar = 'Hello'
myvar += ' world'
myvar += '!'
puts myvar
puts 'Bye!'
Trying to debug it:
>ruby -rdebug myapp.rb
<...>/ruby-2.7.2-1/lib/ruby/2.7.0/x64-mingw32/continuation.so: warning: callcc is obsolete; use Fiber instead
Debug.rb
Emacs support available.
<...>/ruby-2.7.2-1/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:172: if RUBYGEMS_ACTIVATION_MONITOR.respond_to?(:mon_owned?)
(rdb:1) help
Debugger help v.-0.002b
Commands
b[reak] [file:|class:]<line|method>
b[reak] [class.]<line|method>
set breakpoint to some position
. . .
c[ont] run until program ends or hit breakpoint
. . .
Ok, let's do it:
(rdb:1) b myapp.rb:1
Set breakpoint 1 at D:/temp/r/myapp.rb:1
(rdb:1) cont
Hello world!
Bye!
Actual behavior: doesn't stop at breakpoints.
Expected behavior: must stop at breakpoints.
Used gdb for C/C++ and pdb for Python. They have similar interface and work.
The questions are:
Please tell if you can reproduce this problem.
What is the reason of this problem?
Is this a bug or a feature?
How to make the debugger stop at breakpoints?
Could not google the answer. There's an example here (in the end of the page) that, to my mind, doesn't expressly show the expected breakpoint behavior. As the author didn't demonstrate this simple and obvious use case then there must be a problem here.
UPDATE
Checked in Linux -- works as expected.
Try specifying the absolute filename of the program, in other words try running the program as ruby -rdebug $PWD/myapp.rb
I posted a bug report for version 2.7.2 just now:
https://bugs.ruby-lang.org/issues/17492?next_issue_id=17491
Tried with a previous version of Ruby 2.5.3 -- works as expected. The same is on Linux:
$ ruby -rdebug myapp.rb
/usr/lib/x86_64-linux-gnu/ruby/2.5.0/continuation.so: warning: callcc is obsolete; use Fiber instead
Debug.rb
Emacs support available.
myapp.rb:1:myvar = 'Hello'
(rdb:1) b 3
Set breakpoint 1 at myapp.rb:3
(rdb:1) c
Breakpoint 1, toplevel at myapp.rb:3
myapp.rb:3:myvar += '!'
Probably the problem is in the new version or with my installation in Windows.

Not able to get result for def using ruby on mac osx

This is just a sample method I have created for testing purpose using Ruby on Mac OSX 10.12 but I don't get the desired output: Can anyone suggest please? I tried getting the result using both paranthesis and without (). It doesn't even throw any error.
def hi
puts "Hello World"
End
hi
hi()
hi("Hello Matz")`
Try this:
def hi
puts "Hello World"
end
hi
hi()
And this:
def greet(greeting)
puts greeting
end
greet("Hello Matz")
Note that in this line:
hi("Hello Matz")`
you have a tick mark at the end, so that is an error:
1.rb:5: syntax error, unexpected tXSTRING_BEG, expecting end-of-input
It doesn't even throw any error.
Then you aren't running that program.
I suggest you open a Terminal window (Applications/Utilities/Terminal.app), and type in:
$ vimtutor
vim is a free computer programming editor that comes with your Mac. Do the tutorial and learn how to use vim. To run a ruby program, you enter your code into a file, then save it as, say, my_prog.rb. Then you need to give that file to ruby to execute it. You execute a ruby program like this:
$ ruby my_prog.rb
You can create a directory for all your ruby programs like this:
$ mkdir ruby_programs
$ cd ruby_programs
To create a new file inside that directory, use vim:
~/ruby_programs$ vi my_prog.rb
Once you are done typing in your code, save the file, which will put you back at the prompt in Terminal, then you can run your program:
~/ruby_programs$ ruby my_prog.rb
Once you get comfortable with vim, and you feel confident running your ruby programs, consider installing macvim with the vivid chalk color scheme:
It's nicer to look at than plain vim.
Try editing your file so that it reads:
def hi
puts "Hello World"
end
hi
Some important differences to note: def and end are both case-sensitive. The inside of the function definition is indented by two spaces. Since the function takes no arguments, no parentheses are necessary on the call to hi on line 4.
Depending on your filename, enter the command ruby FILENAME and you should see the output Hello World
Ruby keywords are case sensitive. Your code uses End and you probably wanted to use end to mark the end of the hi method.
Because End is not the same as end (and End is not a keyword), irb keeps waiting for input and treats the other three lines as part of the hi method. As far as it can tell, its definition is not complete until it reaches the end keyword (all non-capital letters.)
The correct way to define the method is:
def hi
puts "Hello World"
end
Then you can call it using either hi or hi().
Calling it as hi("Hello Matz") (or hi "Hello Matz") throws an ArgumentError exception with the message wrong number of arguments (given 1, expected 0) because it is called with one argument but the definition of method hi doesn't specify anything about arguments (by its definition, the method hi doesn't accept any argument).

puppet ruby wrong number of arguments (1 for 0)

First off, I know there are a lot of questions regarding this error and I have checked them all, mine is not solved using any of their solutions however.
I am working for the first time with Puppet / Ruby and am having the following issue.
I created this function:
module Puppet::Parser::Functions
newfunction(:phpversion, :type => :rvalue) do
%x["/usr/bin/php -r 'echo PHP_MAJOR_VERSION . \".\" . PHP_MINOR_VERSION;'"]
end
end
And when I call it in my manifest file using:
$phpversion = phpversion()
It throws, when I execute the agent, the error "Error: Could not retrieve catalog from remote server: Error 400 on SERVER: wrong number of arguments (1 for 0) at /etc/puppetlabs/puppet/modules/x/manifests/somefile.pp:123 on node foo.example.bar"
I tried adding |args| after the do statement and removing :type but it keeps throwing the same error. when I use $phpversion = phpversion it just thinks its a text string instead of a function (which I expected, but tried anyway).
Any help would be greatly appreciated.
If you're trying to get the version of php, it'd probably be easier to do it as a fact:
Facter.add(:phpversion) do
setcode do
if Facter::Util::Resolution.which('php')
Facter::Util::Resolution.exec('/usr/bin/php -r 'echo PHP_MAJOR_VERSION . \".\" . PHP_MINOR_VERSION;'"').lines.first.split(/"/)[1].strip
end
end
end
Put this a directory lib/facter/ in your module, then reference it in your manifest as $::phpversion

Resources