Lua:功能和用户输入?

时间:2016-08-07 06:17:20

标签: lua

我正在尝试在lua中执行一个简单的程序,其目的是根据用户输入返回具有特定值的字符串,但是我遇到了脚本问题。

例如,如果我编译

person1 = {
name = "bob" ,
age = 70 ,
hair = "black" ,
};
person2 = {
name = "dan",
age = 40 ,
hair = "blonde" , 
};
describe = function(parent)
print ( "hello " .. parent.name .. " your are " .. parent.age .. " years old
and your hair color is " .. parent.hair )
end
print ("who are you") ;
answer = io.read ();
describe (answer) 

我希望如果我写person1作为输入,脚本将返回一个字符串:

  你好鲍勃,你70岁,头发颜色是黑色

但是它会返回错误。

问题是,我该怎么做才能解决这个问题?在Lua中使用用户输入的正确方法是什么?

1 个答案:

答案 0 :(得分:1)

您必须将select *, 'Table 1' as table_identity from [table 1] Union All select *, 'Table 2' as table_identity from [table 2] Order by Product_id 传递给函数,而不是名称。或者在全局范围内搜索对象:

object

工作示例:http://ideone.com/UJxnpx