Skip to content

[ feature ] embed native language support #55

Closed

Description

@std-microblock

It would be cool if there's a way to directly use native languages in typescript!

Take rust as an example ( as it's also using LLVM, it would probably be easier to implement )

// main.ts
import { read_file } from "./config.rs"

function main(){
    let config = read_file('./config.ini').value;
}
// config.rs
use std::fs::File;
use std::io::prelude::*;
use std::io::Error;

fn read_file(path: &str) -> Result<String, Error> {
    let mut file = File::open(path)?;
    let mut contents = String::new();
    file.read_to_string(&mut contents)?;

    Ok(contents)
}

This would not only bring the great stdlib and other libraries of the language to this TSC but also take advantage of the language's strong points!

Activity

  1. ASDAlexander77 commented on Aug 6, 2023

    @ASDAlexander77
    Owner

    Have a look at project \TypeScriptCompiler\docs\how\cmake_vulkan\ you will see how to use native libraries with typescript native compiler.

  2. ASDAlexander77 commented on Aug 6, 2023

    @ASDAlexander77
    Owner

    FYI: TypeScript compiles code in the same way as any C compiler. so u can reference any function in C code and any C function in TypeScript Native Compiler ... as all code will be compiled into OBJ files LINKER will resolve names.

  3. ASDAlexander77 commented on Aug 6, 2023

    @ASDAlexander77
    Owner

    second option can be to use ''import "./dll.dll"'' and then you can provide function names with "@dllimport" attributes

    for example. if you have dll with function "point"

    type Point = { x: number; y: number; };
    
    import "./<any_dll_file_without_extention_name>"
    
    @dllimport
    declare function point (x: number, y: number): Point;
    
    function main() {
        const p = point (1.0, 2.0);
        print(`x=${p.x}, y=${p.y}`);
    
        print("done.");
    }
  4. Repository owner locked and limited conversation to collaborators on Aug 6, 2023
  5. converted this issue into a discussion #56 on Aug 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions