Implementing parts of stdlib in Haxe
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
- Issue type
- Feature
- Clarity
- Needs clarification
- Activity status
- Quiet
- Tech stack
- cpp
- Domain
- backend, build-system
Research direction
Start by reviewing the existing Sys, File, and FileSystem implementations, the hxcpp build tool, and the marshalling extern types used in the examples. Determine how platform-specific shared objects would be built and cached, and how compatibility between Haxe versions and stdlib implementations would be handled; the issue does not define acceptance criteria for completion.
Written by the indexing model from the issue text.
Description
I've been playing around with the Win32 API with the new marshalling extern types and have been quite pleased with how painless and "just works" it's been. This got me thinking that it would be quite nice if we could write the implementation of stuff like the Sys, File, and FileSystem class in Haxe.
E.g. Here's two functions for the file system class.
class FileSystem {
public static function exists(path:String):Bool {
final count = Utf16.getByteCount(path);
final buffer = Scratch.alloc(count.toInt() + 2);
if (count != Utf16.encode(path, buffer.view)) {
throw new Exception("Failed to encode string to UTF16");
}
return Shell.pathFileExists(buffer.view.reinterpret().ptr);
}
public static function isDirectory(path:String):Bool {
final count = Utf16.getByteCount(path);
final buffer = Scratch.alloc(count.toInt() + 2);
if (count != Utf16.encode(path, buffer.view)) {
throw new Exception("Failed to encode string to UTF16");
}
final result = FileApi.getFileAttributes(buffer.view.reinterpret().ptr);
if (result == FileApi.invalidFileAttributes) {
throw new Exception("Failed to get file attributes");
}
return (result & FileApi.fileAttributeDirectory) != 0;
}
}
and one for the sys class
class Sys {
public static function getEnv(v:String):String {
final nameCount = Utf16.getByteCount(v);
final nameBuffer = Scratch.alloc(nameCount.toInt() + 2);
if (nameCount != Utf16.encode(v, nameBuffer.view)) {
throw new Exception("Failed to encode string to UTF16");
}
final envCount = Win32.getEnvironmentVariable(nameBuffer.view.reinterpret().ptr, null, 0);
final envBuffer = Scratch.alloc(envCount * 2);
if (envCount != Win32.getEnvironmentVariable(nameBuffer.view.reinterpret().ptr, envBuffer.view.reinterpret().ptr, envCount)) {
throw new Exception("Return value was not the expected size");
}
return Utf16.decode(envBuffer.view);
}
}
Obviously this raises lots of questions, such as
- The hxcpp build tool would probably need to build and cache shared platform specific obs which are linked with user code (e.g. hxcpp-file-win32.obj, hxcpp-sys-unix.obj).
- Managing compatibility between haxe versions and std lib implementations in hxcpp could be tricky.
- Many other things.
I have given these no thoughts yet so don't have any answers, I'm not even sure if it's really worth it in the end. But in general I'm in favour of less C++ and I think the new marshalling types gives us a nice path to have that.
- Dominant language
- C++
- Stars
- 330
- Forks
- 237
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 20
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from HaxeFoundation/hxcpp
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
HaxeFoundation/hxcpp#1217 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 18/100
HaxeFoundation/hxcpp#1470 · 4 comments ·
Maintainers usually reply within 1 day
-
bug regression
Difficulty 3/5 1-2 days Newbie friendliness 40/100
HaxeFoundation/hxcpp#1464 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 4/5 1-2 days Newbie friendliness 18/100
HaxeFoundation/hxcpp#1454 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
HaxeFoundation/hxcpp#1452 ·
Maintainers usually reply within 1 day
All issues in HaxeFoundation/hxcpp
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
-
Solution YAML loader rejects comments and blank lines before nested settingsPossibly taken @labishbardiya claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
RunanywhereAI/runanywhere-sdks#1345 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
-
good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
CachyOS/packageinstaller#156 ·
Maintainers usually reply within 2 days