pjh 发表于 2024-3-8 21:09:40

判断当前平台- 代码分享

本帖最后由 pjh 于 2024-3-8 21:17 编辑

用M系列屏幕时,有"在实体机对文件不能直接使用io库操作,在模拟器上不可以对sd卡进行操作"的限制
这种情况下, 设计和proof of concept期间上实体机会增加调试时间. 做两套不同的实现,在运行时判断平台执行相应的代码,可以减少调试时间
故写了一个判断平台的代码,这样可以在运行时检测当前的平台

local platform = {
    unknown = 0,
    emulator = 1,
    real_machine = 2
}


---获取当前的平台
---@return integer
local function get_platform()
    local path_separator = package.config:sub(1, 1)
    debug_print("path_separator: " .. path_separator)
    if path_separator == '\\' then
      debug_print("running on emulator") -- that's windows
      return platform.emulator
    elseif path_separator == '/' then
      debug_print("running on real machine")
      return platform.real_machine
    else
      return platform.unknown
    end
end


dctechnology 发表于 2024-3-11 11:09:30

M系列实体屏不支持io操作,M有专用的读写文件API,https://doc.gz-dc.com/LUA/09_Mfile.html

pjh 发表于 2024-3-11 22:39:44

dctechnology 发表于 2024-3-11 11:09
M系列实体屏不支持io操作,M有专用的读写文件API,https://doc.gz-dc.com/LUA/09_Mfile.html ...

我写了两套代码分别可以运行在模拟器和实机,太丑了就不分享了
页: [1]
查看完整版本: 判断当前平台- 代码分享