Lua中Load函数执行时出现问题
print("i", "j", "i & j")
for i = 0,1 do
for j=0,1 do
print(i, j, i & j)
end
end
上面的代码在Lua中运行良好。它给出以下输出。
i j i & j
0 0 0
0 1 0
1 0 0
1 1 1
但是下面的代码不起作用。基本上我想根据一些用户输入生成真值表。加载功能似乎有问题。可能与函数加载处理的变量类型有关。有人可以建议吗?我们可以编写Lua函数来实现同样的功能吗?这是不起作用的代码。
str="i & j"
print("i", "j", "i & j")
for i = 0,1 do
for j=0,1 do
print(i,j,load(str))
end
end
print("i", "j", "i & j")
for i = 0,1 do
for j=0,1 do
print(i, j, i & j)
end
end
The above code works fine in Lua. It gives the following output.
i j i & j
0 0 0
0 1 0
1 0 0
1 1 1
However the following code doesn't work. Basically I want to generate Truth Table based on some user input. There seems to be issue with load function. Probably it is related with type of variable that function load handles. Can anyone suggest? Can we write Lua function to achieve same? Here is the code that doesn't work.
str="i & j"
print("i", "j", "i & j")
for i = 0,1 do
for j=0,1 do
print(i,j,load(str))
end
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个应该最多可处理近六十个值的尝试:
Here's an attempt which is supposed to work with a maximum of nearly sixty values:
使用小技巧:
use little tricks: