V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
slimbloody
V2EX  ›  程序员

初学者几个Lua的问题

  •  
  •   slimbloody · 2013-05-07 18:51:25 +08:00 · 3296 次点击
    这是一个创建于 3978 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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.
    2 条回复    1970-01-01 08:00:00 +08:00
    luikore
        1
    luikore  
       2013-05-07 19:06:18 +08:00   ❤️ 1
    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
        2
    xatest  
       2013-05-07 19:39:09 +08:00   ❤️ 1
    @luikore 说得很清楚了,我补充几句:
    1. 用"还是'都可以,只是不同的风格,没有对错之分。我看到的很多开源代码里都是用",所以就保持一致了。我们团队也约定了在这类风格问题上保持一致,例如在结尾都没有;分号。不确定的时候多读读开源代码就行了。
    4. Lua的number实际上是双精度实数,四舍五入的问题是指有些语言在整数运算时,会出现应该四舍五入却没有正确四舍五入的问题,例如3-2=0.999999这样。在Lua里,用双精度实数表示32bit范围内的整数,是精度足够的,可以正确地进行整数运算,不会出现四舍五入错误的问题。
    5. Lua是靠解释器执行的,解释器是开源的你可以自己编译,编译之前把修改源码,把lua number的定义改成long或者单精度实数也是允许的,这在某些不支持双精度浮点运算的硬件平台上很有用。例如某些嵌入式设备,只有整数运算而没有浮点数运算,我以前做J2ME开发的时候就碰到过。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1546 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 17:11 · PVG 01:11 · LAX 10:11 · JFK 13:11
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.