libimportx banner

libimportx

8 devlogs
18h 8m 41s

Call functions written in other languages as if it's the same language!
NOTE: This is currently only written in Python, i will write it in JS and other languages next ship
it IS kinda useless now but i am having to ship now instead of later …

Call functions written in other languages as if it’s the same language!
NOTE: This is currently only written in Python, i will write it in JS and other languages next ship
it IS kinda useless now but i am having to ship now instead of later because of lockin sidequest please dont vote less because of this pls

This project uses AI

I used AI for one test. Specifically testtheclient.sh in itzmetanjim/libimportx-python. Everything else is AI-free.

Demo Repository

Loading README...

tanjim

Implement everything needed for importx

Because JS is JS, I can’t use normal blocking socket reads, instead i have to use this weird structure of promises, like I think async functions and promises are awesome but like when some things need promises and some things (unix socket API) do not have promises i have to make this weird linking layer which involves things like:

  • attaching a .then to a function to trick JS into thinking it’s some weird function-promise object, then use Proxy on that mutant to make a weird kind of object thats a function and can be await’ed and can also have properties set and accesses and all properties are also this cursed thing
  • returning a manual promise (without async) and resolving/rejecting it OUTSIDE THE FUNCTION like i send a promise but another function wayy outside resolves it?

(sorry for the code screenshot but since this devlog is only a stepping stone (it does not implement importx yet, just the framewrok underneath), i dont have any output to show

Attachment
0
tanjim

Implemented exportx (and all required functions it depends on) in the JS implementation

now i have 2 languages with implementations (python,JS) so i can test it out. look in the screenshot, it should seem cursed to you if you are a normal person like im importing a js file as if its nothing and its just seamless, i can even move around unserializable objects (even files, not shown).

Changelogs

in libimportx-js (most relevant to this ship):

in libimportx:

Attachment
0
tanjim

Implement importx() ImportxOpaque ImportxModule ImportxNamespace

yay! now it is essentially done. you can use it now

however its currently essentially useless since i did not implement it in any language other than python yet

Changelog

in libimportx-python

Attachment
0
tanjim

Made the exportx implementation in Python

i made the python implementation for exportx and also some tests for it

Changelog

in libimportx

for pesky ft reviewers: the screenshot is technically “output” not “code”
for normal people the screenshot shows me testing the client:

  • first the thing that is exporting send over the token, it is correct so i send +
  • now i send a request to read the variable und which does not exist, so the client returns an error, errors are prefixed with minus
  • then i read mydict which is successful so its prefixed with plus
  • i try to read a file but files cant be sent over JSON so it uses this special syntax. i can still interact with the file using its methods
  • i try to read a function similar story
  • i call the function a few times, the function is supposed to return true then false then so on which it does
  • i try to read the json module however modules cant be sent over JSON
  • i try to read the function json.dumps
  • i try to call json.dumps but i didnt put any args so it errors
  • i made a mistake with the next one, i forgot to make the args an array so the client thought each char was an argument
  • then i call it correctly (twice) and it works
Attachment
0
tanjim

Refine the protocol

yeah turns out the previous one had many errors and was unimplementable so i fixed than and made it better

  • The JSON output always starts with + or - for success and error. This means I can read one byte to see if it is successful or not.

  • Dynamically generated functions (like functions returning functions) could not be serialized before because they didn’t have an identifier as they were not in any variable. Now it allows both static and dynamic functions.

  • Compiled languages and languages which dont use # for comments would straight up not work since without a shebang the OS would not be able to figure out how to run it. Now the library itself figures it out.

  • Data that could nto be serialized (eg file objects) would not work, now it just uses a special opaque type. so objects that dont exist/cant be moved to the other language can be used as well. (so i could write to a file object through languages!)

Changelog

here is a diagram i made to explain how the opaque object thing works.

Attachment
0
tanjim

Document the api

wait what im documenting it before making it?? yes you heard that right. the reason im doing this is for procastination so that i have a clear and consistent implementation plan. i will have to make this in a million languages so im making sure i dont have to improvise

Changelog

here is this diagram i made to explain the protocol loosely

Attachment
0