file_lualike 0.1.0 copy "file_lualike: ^0.1.0" to clipboard
file_lualike: ^0.1.0 copied to clipboard

Adapter that bridges package:file FileSystem implementations (SFTP, memory, local) into the lualike scripting runtime. Enables transparent filesystem backends for io.open(), os.remove(), dofile(), and [...]

file_lualike #

Pub Version Pub Version License

Bridges package:file FileSystem implementations into the LuaLike scripting runtime. Enables transparent filesystem backends for io.open(), os.remove(), dofile(), module loading, and all other lualike file operations.

Use any package:file-compatible filesystem — local disk, in-memory (MemoryFileSystem), SFTP (file_sftp), or a custom implementation — without changing a single line of Lua code.

Install #

dependencies:
  lualike: ^0.2.2
  file_lualike: ^0.1.0

Then run:

dart pub get

Dependencies #

Package Version Purpose
file ^7.0.1 package:file FileSystem abstraction
lualike ^0.2.2 Runtime to bridge into

Quick start #

import 'package:lualike/lualike.dart';
import 'package:file_lualike/file_lualike.dart';
import 'package:file/local.dart';

Future<void> main() async {
  final lua = LuaLike();

  // Use the local filesystem (dart:io under the hood)
  await useFileSystem(const LocalFileSystem());

  lua.expose('greet', (List<Object?> args) {
    return Value('Hello, ${args.first ?? 'world'}!');
  });

  final result = await lua.execute('''
    local f = io.open("/tmp/hello.txt", "w")
    f:write("Hello from LuaLike!")
    f:close()
    return greet("file written")
  ''');

  print((result as Value).unwrap());
}

Usage #

Wiring into lualike #

Call useFileSystem(fs) once during setup. It wires two integration points:

  1. File providerio.open(), io.lines(), etc. create PackageFileIODevice instances backed by your FileSystem.
  2. Metadata backendos.remove(), dofile(), module loading, and other filesystem metadata operations delegate to your FileSystem.
await useFileSystem(yourFileSystem);

In-memory filesystem (testing) #

import 'package:file/memory.dart';
import 'package:file_lualike/file_lualike.dart';

final fs = MemoryFileSystem();
await useFileSystem(fs);

// All file operations now happen in memory

SFTP filesystem (remote) #

import 'package:file_lualike/file_lualike.dart';
import 'package:file_sftp/file_sftp.dart';

final sftp = SftpFileSystem(SftpConfig(
  host: 'example.com',
  username: 'alice',
  password: 'secret',
  root: '/home/alice/project',
));

await useFileSystem(sftp);

// All file operations transparently go over SFTP

Custom FileSystemProvider #

For advanced scenarios where you need fine-grained control over the provider:

final provider = FileSystemProvider();
await useFileSystem(fs, provider: provider);

Targeted provider override #

If you need only the metadata backend without changing the I/O provider:

import 'package:lualike/lualike.dart';

setFileSystemBackend(PackageFileSystemBackend(fs));

How it works #

file_lualike provides two adapters:

Adapter Interface Role
PackageFileIODevice IODevice Opens a package:file File as a lualike I/O device. Supports buffered reads/writes, seeking, and all standard lualike I/O modes ("r", "w", "a", "r+", "w+", "a+", with optional "b").
PackageFileSystemBackend FileSystemBackend Delegates metadata operations (fileExists, readFileAsString, createDirectory, renameFile, etc.) to a package:file FileSystem.

Both adapters work with any FileSystem implementation — local, SFTP, in-memory, or custom.

All methods return safe defaults (false, null, or empty collections) instead of throwing on transient errors, matching lualike's error-handling conventions.

0
likes
0
points
172
downloads

Publisher

verified publisherglenfordwilliams.com

Weekly Downloads

Adapter that bridges package:file FileSystem implementations (SFTP, memory, local) into the lualike scripting runtime. Enables transparent filesystem backends for io.open(), os.remove(), dofile(), and all other lualike file operations.

Repository (GitHub)
View/report issues

Topics

#lua #scripting #filesystem #sftp #adapter

License

unknown (license)

Dependencies

file, lualike

More

Packages that depend on file_lualike