Lua检查文件是否打开 [英] Lua check if a file is open or not

查看:134
本文介绍了Lua检查文件是否打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写lua文件的脚本,以检查某个文件是否已打开.然后,我希望它关闭该文件(如果已打开).我知道如何检查文件是否存在,但是我需要知道如何检查文件是否打开,这意味着文件正在运行.

I'm trying to script a lua file to check if a certain file is open. Then I want it to close that file if it is open. I know how to check if the file exist but I need to know how to check if the file is open, meaning the file is running.

推荐答案

Lua与C,C ++以及几乎所有其他语言一样,只能关闭打开自身的文件.您不能关闭其他人打开的文件(不能通过标准的Lua调用);这将是令人难以置信的粗鲁.

Lua, like C, C++, and pretty much every other language, can only close files that it opens itself. You cannot close files open by other people (not with standard Lua calls); this would be incredibly rude.

因此,您无法测试文件是否被其他人打开.您也无法关闭文件.您可能需要执行系统API调用,但是您必须自己给Lua脚本访问这些API的权限. Lua的标准库无法做到这一点.

So you can't test to see if a file is opened by someone else. Nor can you close their file. There may be system API calls you could make to do this, but you would have to give Lua scripts access to those APIs yourself. Lua's standard libraries can't do this.

这篇关于Lua检查文件是否打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆