2

I'm trying to pick up Lua programming but I'm stuck on something that's probably trivial. I'm prototyping some Lua scripts using Kahlua from IntelliJ Idea 11 and I keep getting errors whenever I try to use io.read(). Here's what I currently have:

require "io"

print("input:")
a = io.read()        -- read a number
print(a)

When I run it in Idea I get "Tried to call nil at interpreter:1" If I remove the require and the blank line after it I get "input: attempted index of non-table: null at interpreter:2" What am I doing wrong?

Cliff
  • 10,586
  • 7
  • 61
  • 102

2 Answers2

2

Kahula doesn't support the io library.

Your best bet would be to set up a real Lua SDK, and use the run lua console feature.

See: http://www.screencast.com/t/0f262SeCKmqT

sylvanaar
  • 8,096
  • 37
  • 59
  • I finally figured the same on my own back in February. I'd been running via the console feature ever since. – Cliff Mar 29 '12 at 21:19
0

Perhaps this? (adding local io to the beginning)

local io = require "io"

print("input:")
a = io.read()        -- read a number
print(a)
Garrett Bluma
  • 1,312
  • 10
  • 14
  • Nope, I think it's a bug in the plugin. The normal Lua runtime accepts all flavors of my code just fine. One of those toe-stubbers of picking up a new language by using an IDE plugin. – Cliff Feb 03 '12 at 17:01