Skip to content

nomota/ext.c3l

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ext.c3l - extended C3 library

An extended library for the C3 programming language, providing essential system-level functionality, networking capabilities, and cross-platform C header bindings, and more

Overview

ext.c3l bridges the gap between C3 and system-level programming by providing:

  • C header bindings (POSIX and Win32)
  • Networking APIs (TCP, UDP, DNS)
  • File system and I/O utilities
  • Regular expression support
  • Fiber coroutine
  • Async I/O (Python-like)
  • Async File I/O (Python-like)

Why ext library?

C3 standard library is minimalistic, lacks something. Ext library fills the gap.

Installation

Prerequisites

First, install the c3l library manager:

git clone https://github.com/konimarti/c3l
cd c3l
sudo make install

Adding ext.c3l to your project

In your C3 project directory, fetch the library by:

c3l fetch https://github.com/nomota/ext.c3l

This will download the library as a zip-packed file: lib/ext.c3l.

And in your project.json

    "dependancies": [ "ext" ],

Now it's ready to be used in your project.

Available library modules

C Header Bindings

Provides bridge modules to C header files for both POSIX and Windows platforms:

C Header C3 Module Import Statement
stdio.h stdio.h.c3 import c::stdio;
unistd.h unistd.h.c3 import c::unistd;
netinet/in.h netinet.in.h.c3 import c::netinet::in;
winsock2.h winsock2.h.c3 import c::winsock2;
... ... ...

Import your familiar C header files.

import c::stdio;
import c::string;
import c::errno; // provides errno(), get_fault()
import c::sys::time; // POSIX
import c::netinet::in; // POSIX
import c::unistd; // POSIX

import c::io; // Win32
import c::process; // Win32
import c::winsock2; // Win32
import c::ws2tcpip; // Win32

sidio::printf("Hello\n");

winsock2::WSAData wsa_data;
int result = winsock2::wsa_startup(0x0202, &wsa_data);

UdpSocket? sock = (UdpSocket)winsock2::socket(winsock2::AF_INET, winsock2::SOCK_DGRAM, winsock2::IPPROTO_UDP);

Networking

High-level networking capabilities including TCP, UDP, and DNS:

Module Description
ext::io::tcp TCP operations: new(), new_listen(), listen(), connect(), accept(), send(), recv(), read(), write(), readline(), set_non_blocking(), close()
ext::io::udp UDP operations: new(), new_bind(), bind(), send(), recv(), sendto(), recvfrom(), set_non_blocking(), close()
ext::io::dns DNS operations: get_addrinfo()

I/O Operations

File system operations including stat, directory handling, and file utilities:

Module Description
ext::io::stat File stat operations: exists(), size(), is_(file/dir/link), is_(readable/writable/executable), read_link(), link(), symlink(), last_modified(), change_mode()
ext::io::cfile File operations: open(), close(), read(), read_byte(), write(), write_byte(), printf(), seek(), tell(), eof(), load(), save(), copy(), rename(), remove(), exists(), size(), last_modified(), is_file(), is_dir(), change_mode()
ext::io::dir Directory/folder operations: get_cur_dir(), change_dir(), make_dir(), remove_dir(), rename(), list_dir(), exists(), is_dir(), is_file(), change_mode(), scan_dir()

Hash Operations

Module Description
ext::hash::murmur MurmurHash3 functions: hash3_x86_32(), hash3_x86_128(), hash3_x64_128()
ext::hash::city CityHash functions: hash64(), hash64_with_seed(), hash128(), hash128_with_seed(), hash128_crc(), hash128_ rc_with_seed()

Regular Expressions

Regex support for C3 based on C regex library.

Module Description
ext::regex RegEx operations: new_compile(), match(), group(), free(), replace(), split(), reg_match(), reg_replace(), reg_split();
slre SLRE operations: compile(), match(), reg_match(), reg_replace()

Fiber coroutine

It provides a lightweight cooperative multitasking system, allowing you to create and switch between multiple execution contexts (fibers) within a single thread.

Based on:

  • X86_64, AARCH64: Assembly code, fast switching
  • Windows: Native Fiber interface
  • Other Posix: based on sigsetjmp() /siglongjmp()
Module Description
ext::thread::fiber Fiber operations: create(), delete(), active(), switch_to(), yield()

Async I/O

This is a C3 version of Python's asyncio library. It follows the python's API, because it is the easiest one among its kind.

It's based on C3's fiber coroutine.

Module Description
ext::asyncio Python asyncio-similar operationsFuture, Task, EventLoop, Stream, Datagram, Transport, Protocol, DatagramProtocol

Asynchronous Non-blocking file I/O

Asynchronous, non-blocking file I/O on top of ext::asyncio framework. API is mostly like in Python.

Module Description
ext::aiofiles Asynchronous file operations: open(), file_size(), read(), write(), readline(), read_unbuffered(), at_eof(), read_until(), writef(), flush(), seek(), tell(), truncate(), stdin(), stdout(), stderr()
ext::aiofiles::os Asynchronous os operations: stat(), rename(), replace(), remove(), mkdir(), makedirs(), rmdir(), removedirs(), listdir(), scandir(), link(), symlink(), readlink()
ext::aiofiles::os::path Asynchronous Directory/folder operations: exists(), getsize(), isfile(), isdir(), islink()
ext::aiofiles::tempfile` Asynchronous tempfile operations: temporaryFile(), temporaryDirectory()

Debugging macros

ext::debug is for giving debugging macros within a library.

Module Description
ext::debug Debugging macros: warn(), @assert()

Memory allocation macros

ext::mem is for giving memory allocation macros within a library.

Module Description
ext::mem Allocation macros: set_allocator(), mem_alloc(), mem_malloc(), mem_alloc_array(), mem_copy(), mem_copy_str(), mem_free(), temp_alloc(), temp_malloc(), temp_alloc_array(), temp_free(), LocalAllocator

Serializer - various encoder/decoder

ext::serializer module is to fill missing gaps of C3 std lib by providing various encoders/decoders.

Module Description
ext::serializer::json JSON serializer: JsonObject, JsonArray, JsonMap, JsonNull, JsonBool, JsonNumber, String, bool, long, double, null, decode(), encode()
ext::serializer::http HTTP/1.x parser: Request, Response, Url, SetCookie, FormFile, KeyValue, parse_request(), parse_response(), decode helpers

Usage examples

Platform Support

  • POSIX systems (Linux, macOS, BSD variants)
  • Windows (Win32 API support)

Cross-platform compatibility is a primary goal, with platform-specific implementations abstracted behind unified APIs where possible.

Contributing

Contributions are welcome! When submitting pull requests:

  1. Ensure cross-platform compatibility
  2. Update relevant README files in sub-libraries
  3. Follow existing code style and conventions
  4. Test on both POSIX and Windows platforms when applicable

Repository

GitHub: https://github.com/nomota/ext.c3l

License

MIT License


For detailed documentation on specific modules, please refer to the README files in each subdirectory under ext/.

About

Extended library for C3 language

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors