Cliff
Cliff

Reputation: 11248

Lua Newbie stuck on simple input

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?

Upvotes: 2

Views: 1308

Answers (2)

sylvanaar
sylvanaar

Reputation: 8216

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

Upvotes: 2

Garrett Bluma
Garrett Bluma

Reputation: 1312

Perhaps this? (adding local io to the beginning)

local io = require "io"

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

Upvotes: 0

Related Questions