初学者几个Lua的问题

2013-05-07 18:51:25 +08:00
 slimbloody
1.geting start
literal string ""
single charator ''
string that are used as pattern '' eg: '[%w_]'
书本后面又说用“”和‘’都可以,选择一种正确的形式就可以,到底要不要遵循这个规定呢?而且看了例子还是不理解pattern
2.如果Lua代码里有两个函数同名的函数怎么办
eg: % lua -e "print(math.sin(x))"
x = 1
print(math.sin(x))
x = 2
print(math.sin(x))
x在不同区段的值不一样,那到底是输出哪个函数呢?
3.for instance in the use of nil to differentiate a normal return value from an abnormal condition.求具体的例子
4.a Lua number can represent any 32-bit integer without rounding problems整数怎么会出现四舍五入?
5.it is easy to compile Lua so that it uses another type for numbers, such as longs or single-precision floats. This is particularly useful for platforms without hardware support for floating point. 求解释
6.luaconf.h 在哪里?(ubuntu 12.04)
7.Strings in Lua have the usual meaning: a sequence of characters.Lua is eight-bit clean and its strings may contain characters with any numeric code,including embedded zeros. This means that you can store any binary data into a string
8.Moreover, this form ignores the first character of the string
when this character is a newline.
3309 次点击
所在节点    程序员
2 条回复
luikore
2013-05-07 19:06:18 +08:00
1. 意思是说没有规定... pattern 是啥你看下去就知道了
2. 两个同名函数, 后定义的覆盖前面的. 你要定义区间函数的话, 在一个函数里判断 x 的区间
3. 例如你可以定义一个函数 add(a, b), 如果 a 和 b 都是 number 你就返回 a + b, 如果 a 或 b 不是 number 你就返回 nil 表明接收到了异常的输入.
4. 你理解反了, without 不是 with, 意思是用整数就没四舍五入的问题
5. 有些硬件没浮点运算单元的, 你可以先不管
6. #include 就它可以了...
7. 8 问题是什么?
xatest
2013-05-07 19:39:09 +08:00
@luikore 说得很清楚了,我补充几句:
1. 用"还是'都可以,只是不同的风格,没有对错之分。我看到的很多开源代码里都是用",所以就保持一致了。我们团队也约定了在这类风格问题上保持一致,例如在结尾都没有;分号。不确定的时候多读读开源代码就行了。
4. Lua的number实际上是双精度实数,四舍五入的问题是指有些语言在整数运算时,会出现应该四舍五入却没有正确四舍五入的问题,例如3-2=0.999999这样。在Lua里,用双精度实数表示32bit范围内的整数,是精度足够的,可以正确地进行整数运算,不会出现四舍五入错误的问题。
5. Lua是靠解释器执行的,解释器是开源的你可以自己编译,编译之前把修改源码,把lua number的定义改成long或者单精度实数也是允许的,这在某些不支持双精度浮点运算的硬件平台上很有用。例如某些嵌入式设备,只有整数运算而没有浮点数运算,我以前做J2ME开发的时候就碰到过。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/68062

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX