Skip to content

Add io.popen implementation #141

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

kyoh86
Copy link

@kyoh86 kyoh86 commented Jun 23, 2025

Implements the missing io.popen function to execute shell commands from Lua scripts.

Fixes #61

Changes

  • Add io.popen() with read/write mode support using os/exec
  • Fix metatable initialization order in IOOpen
  • Add tests for both read and write modes
  • Update existing test to use string.find instead of unimplemented string.match

Usage

local f = io.popen("echo hello", "r")
local output = f:read("*a")
f:close()

Returns nil, error on failure.

- Add io.popen function supporting both read ('r') and write ('w') modes
- Improve error handling to return nil and error message on failure
- Fix metatable setup order in IOOpen to ensure proper initialization
- Add comprehensive tests for io.popen functionality
- Update test to use string.find instead of unimplemented string.match
- Remove invalid doc_test.go file
@kyoh86 kyoh86 changed the title wip: support 'io.popen' Add io.popen implementation Jun 23, 2025
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It fails now.

$ go test ./...
# github.com/Shopify/go-lua_test
# [github.com/Shopify/go-lua_test]
./doc_test.go:8:1: ExampleFunction should be niladic
./doc_test.go:8:1: ExampleFunction should return nothing
FAIL    github.com/Shopify/go-lua [build failed]
FAIL

@kyoh86 kyoh86 marked this pull request as ready for review June 23, 2025 02:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

panic: runtime error: hello.lua:22: 'popen' not supported
1 participant