gpt4 book ai didi

time - Luaj os.time() 返回毫秒

转载 作者:行者123 更新时间:2023-12-04 22:02:11 26 4
gpt4 key购买 nike

Luaj 中的 os.time() 以毫秒为单位返回时间,但根据 lua 文档,它应该以秒为单位返回时间。

  • 这是Luaj中的错误吗?
  • 你能提出一种适用于 Luaj(for java) 和真正的 Lua(c/c++) 的解决方法吗?因为我必须为两个应用程序使用相同的 lua 源。(不能简单地除以 1000,因为它们都有不同的时间尺度)

  • 我的 lua 文件中的示例:
    local start = os.time()
    while(true) do
    print(os.time() - start)
    end

    在 c++ 中,我收到输出:
    1
    1
    1
    ...(1 seconds passed)
    2
    2
    2

    在 Java( 使用 Luaj )中,我得到:
    1
    ...(terminate in eclipse as fast as my finger can)
    659
    659
    659
    659

    仅供引用,我在 Windows 上试试这个

    最佳答案

    是的,luaj 中有一个错误。

    实现只返回 System.currentTimeMillis()当您调用 os.time() 时。它真的应该返回类似 (long)(System.currentTimeMillis()/1000.) 的东西

    还值得指出的是,luaj 中的 os.date 和 os.time 处理几乎完全缺失。我建议您假设它们尚未实现。

    关于time - Luaj os.time() 返回毫秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16181858/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com