V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
slimbloody
V2EX  ›  程序员

初学者几个Lua的问题

  •  
  •   slimbloody · May 7, 2013 · 3891 views
    This topic created in 4743 days ago, the information mentioned may be changed or developed.
    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 replies    1970-01-01 08:00:00 +08:00
    luikore
        1
    luikore  
       May 7, 2013   ❤️ 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  
       May 7, 2013   ❤️ 1
    @luikore 说得很清楚了,我补充几句:
    1. 用"还是'都可以,只是不同的风格,没有对错之分。我看到的很多开源代码里都是用",所以就保持一致了。我们团队也约定了在这类风格问题上保持一致,例如在结尾都没有;分号。不确定的时候多读读开源代码就行了。
    4. Lua的number实际上是双精度实数,四舍五入的问题是指有些语言在整数运算时,会出现应该四舍五入却没有正确四舍五入的问题,例如3-2=0.999999这样。在Lua里,用双精度实数表示32bit范围内的整数,是精度足够的,可以正确地进行整数运算,不会出现四舍五入错误的问题。
    5. Lua是靠解释器执行的,解释器是开源的你可以自己编译,编译之前把修改源码,把lua number的定义改成long或者单精度实数也是允许的,这在某些不支持双精度浮点运算的硬件平台上很有用。例如某些嵌入式设备,只有整数运算而没有浮点数运算,我以前做J2ME开发的时候就碰到过。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2508 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 08:40 · PVG 16:40 · LAX 01:40 · JFK 04:40
    ♥ Do have faith in what you're doing.