node.input()应该在nodeMCU Lua中处理sting

时间:2015-12-01 04:11:16

标签: lua nodemcu

此代码是否应该执行并将“bar”的值赋给变量baz?

foo = "bar"
baz = "bazza"
cmd = "baz = foo"
node.input(cmd)  
print("this is foo "..foo)
print("this is baz "..baz)

预期输出为:

this is foo bar
this is baz bar

这不是我缺少的东西吗?

1 个答案:

答案 0 :(得分:0)

啊哈哈那一刻,在查看源代码后,似乎使用了一个计时器来执行命令,所以在等待一点后我确实得到了预期的结果。这工作

function launch()
  foo = "bar"
  baz = "bazza"
  cmd = "baz = foo"
  node.input(cmd)  
  print("this is foo "..foo)
  print("this is baz "..baz)

  tmr.alarm( 1 , 50 , 0 , somethingElse )

end

function somethingElse()
  print("this is foo "..foo)
  print("this is baz "..baz)
end

tmr.alarm( 0 , 15000 , 0 , launch )