Lua 中如何对桌面进行截屏

我想将两个显示器上的 Linux 桌面截屏。

根据搜索的结果,我编写了一个简单的代码来实现截屏:

require "display"
local image = display.captureScreen()
display.save( image, { filename="image.png", isFullResolution=true } )

但是它并不能正常工作,并显示了以下错误:

 /home/a/torch/install/bin/luajit: screenshot.lua:2: attempt to index global 'display' (a nil value)

堆栈回溯: screenshot.lua:2: in main chunk [C]: in function 'dofile' ...a/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:150: in main chunk [C]: at 0x00405d50

有什么建议吗?

原文链接 https://stackoverflow.com/questions/52224201

点赞
stackoverflow用户1442917
stackoverflow用户1442917

尝试使用 local display = require "display" 替换第一行代码,因为大多数模块都会返回要使用的值,而不是污染“全局”表。

2018-09-07 14:37:48