Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

io.open 不支持 r+ #5717

Open
q962 opened this issue Oct 15, 2024 · 20 comments
Open

io.open 不支持 r+ #5717

q962 opened this issue Oct 15, 2024 · 20 comments
Labels

Comments

@q962
Copy link

q962 commented Oct 15, 2024

Xmake 版本

xmake v2.9.5+HEAD.d30de52e9

操作系统版本和架构

windows10 22H2

描述问题

io.open 不支持 r+

r+b 不报错,但是不会修改文件

期待的结果

工程配置

	 file = io.open("r.lua", "r+")
	file:seek('set', 0)
	file:write(string.char(0x22))
	file:close()
	print(1)

附加信息和错误日志

error: @programdir\core\main.lua:329: ...mdir\core\sandbox\modules\import\core\sandbox\module.lua:563: cannot import module: r, stack traceback:
    [C]: in function 'error'
    [@programdir\core\base\os.lua:1015]:
    [@programdir\core\sandbox\modules\io.lua:56]: in function 'close'
    [.\r.lua:32]: in function 'a'
    [.\r.lua:38]: in main chunk

stack traceback:
        [C]: in function 'error'
        @programdir\core\base\os.lua:1004: in function 'base/os.raiselevel'
        (...tail calls...)
        @programdir\core\main.lua:329: in upvalue 'cotask'
        @programdir\core\base\scheduler.lua:406: in function <@programdir\core\base\scheduler.lua:399>
@q962 q962 added the bug label Oct 15, 2024
@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Title: io.open does not support r+

Xmake version

xmake v2.9.5+HEAD.d30de52e9

Operating system version and architecture

windows10 22H2

Describe the problem

io.open does not support r+

Unable to modify file

Expected results

Project configuration

file = io.open("r.lua", "r+")
print(file)
file:seek('set', 0)
print(file)
file:write(string.char(0x22))
print(file)
file:close()
print(file)

Additional information and error logs

file(780.000B) "r.lua"

file(780.000B) "r.lua"

file(780.000B) "r.lua"

error: @programdir\core\main.lua:329: ...mdir\core\sandbox\modules\import\core\sandbox\module.lua:563: cannot import module: r, stack traceback:
    [C]: in function 'error'
    [@programdir\core\base\os.lua:1015]:
    [@programdir\core\sandbox\modules\io.lua:56]: in function 'close'
    [.\r.lua:32]: in function 'a'
    [.\r.lua:38]: in main chunk

stack traceback:
        [C]: in function 'error'
        @programdir\core\base\os.lua:1004: in function 'base/os.raiselevel'
        (...tail calls...)
        @programdir\core\main.lua:329: in upvalue 'cotask'
        @programdir\core\base\scheduler.lua:406: in function <@programdir\core\base\scheduler.lua:399>

@waruqi
Copy link
Member

waruqi commented Oct 15, 2024

不支持

@q962
Copy link
Author

q962 commented Oct 15, 2024

会打算支持吗?

不打算的话,那能否暴露 lua 原生 os ?

@waruqi
Copy link
Member

waruqi commented Oct 15, 2024

直接用 w 不行么。

不打算的话,那能否暴露 lua 原生 os ?

不考虑,我全部重写的,原生 io 连 unicode 都不支持

@q962
Copy link
Author

q962 commented Oct 15, 2024

我是要修改二进制文件的,所以无关编码

不行,文件被截断。我尝试过了


function a()
    local filePath = "r.lua"
    local file = io.open(filePath, "wb")
    -- file:seek('set', 2)

    file:write(string.char(0x22))
    file:close()
end

a()

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Will you plan to support it?

If not, can the native OS of Lua be exposed?

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Not supported

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Can't you just use w directly?

If not, can Lua native OS be exposed?

Regardless, I rewrote everything. Native io doesn’t even support unicode.

@waruqi
Copy link
Member

waruqi commented Oct 16, 2024

我是要修改二进制文件的,所以无关编码

我知道,但是我不可能为了支持你这一个需求,重新暴露 lua 原生 io ,废弃掉当前的实现,让其他 99% 的读写,都支持不了 unicode

@waruqi
Copy link
Member

waruqi commented Oct 16, 2024

不行,文件被截断。我尝试过了

那目前不支持,只能等后面有空了再看看了。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


I want to modify the binary file, so the encoding has nothing to do with it

I know, but in order to support your demand, I may re-expose Lua's native io, abandon the current implementation, and make the other 99% of reading and writing unable to support unicode

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


No, the file is truncated. i tried

That’s not supported at the moment, so we’ll have to wait and see when we have time later.

@waruqi
Copy link
Member

waruqi commented Oct 16, 2024

试下这个 patch #5724

不过二进制写入要加 b,用 r+b

@q962
Copy link
Author

q962 commented Oct 16, 2024

我咋试?

github actions 不是可以下载结果的吗?为啥你这个没有下载列表。

@waruqi
Copy link
Member

waruqi commented Oct 16, 2024

xmake update github:xmake-io/xmake#io

@waruqi
Copy link
Member

waruqi commented Oct 16, 2024

我咋试?

github actions 不是可以下载结果的吗?为啥你这个没有下载列表。

这不是有的么 https://github.com/xmake-io/xmake/actions/runs/11366002478?pr=5724

@q962
Copy link
Author

q962 commented Oct 16, 2024

咋还报 : not support to update from unofficial source on windows, missing '--scriptonly' flag?

哦哦,在 windows 里,晓得了。我在 msys2 里找没找到。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


How should I try?

Isn't it possible to download the results from github actions? Why don't you have a download list?

@q962
Copy link
Author

q962 commented Oct 16, 2024

还是不行,存在一个有趣的错误

使用 r+b 模式下,先读后写会导致写无效,无事发生。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Still not working, there is an interesting bug

In r+b mode, reading first and then writing will cause the writing to be invalid and nothing will happen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants