Skip to content

[wip] quickjs/2024-01-13 #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Conversation

luoliwoshang
Copy link
Member

@luoliwoshang luoliwoshang commented Apr 27, 2025

  • temp ignore "quickjs/libbf.h",because the int128_t is not support yet.

  • follow demo wil got NaN.

package main

import (
	"fmt"

	"github.com/goplus/llgo/c"
	"github.com/goplus/llpkg/quickjs"
)

func main() {
	rt := quickjs.JSNewRuntime()
	ctx := rt.JSNewContext()

	jsCode := c.Str("function add(a, b) { return a + b; }\nadd(3, 4);")

	result := ctx.JSEval(jsCode, c.Strlen(jsCode), c.Str("<input>"), 0)

	var v c.Int32T

	if ctx.JSToInt32(&v, result) == 0 {
		c.Printf(c.Str("3 + 4 = %d\n"), v)
	} else {
		fmt.Printf("Failed to convert result to integer\n")
	}

	ctx.X__JSFreeValue(result)

	ctx.JSFreeContext()
	rt.JSFreeRuntime()
}

quickjs/_demo/add on  quickjs [!?] via 🐹 v1.23.4 
❯ llgo run .             
3 + 4 = nan
__JS_FreeValue: unknown tag=73896

c with rpath,got

#include <stdio.h>
#include <string.h>
#include "quickjs/quickjs.h"

int main(int argc, char **argv) {
    JSRuntime *rt = JS_NewRuntime();
    JSContext *ctx = JS_NewContext(rt);

    const char *js_code = "function add(a, b) { return a + b; }\nadd(3, 4);";

    JSValue result = JS_Eval(ctx, js_code, strlen(js_code), "<input>", 0);
    
    double v;
    JS_ToFloat64(ctx, &v, result);
    printf("result : %.0f\n", v);
    
    JS_FreeValue(ctx, result);
    JS_FreeContext(ctx);
    JS_FreeRuntime(rt);
    return 0;
}
 clang \       
  $(pkg-config --cflags quickjs) \
  quickjs_demo.c -o quickjs_demo \
  $(pkg-config --libs quickjs) \
  -Wl,-rpath,/Users/zhangzhiyang/.conan2/p/b/quick9a51aaeb1ccd6/p/lib
result:7

but without rpath,got

goplus-llpkg/t on  quickjs [!?] via C v15.0.0-clang 
❯ ./quickjs_demo
dyld[10313]: Library not loaded: @rpath/libquickjs.dylib
  Referenced from: <4270F2AF-1373-359A-B3C5-05C5CFEC35B5> /Users/zhangzhiyang/Documents/Code/goplus/goplus-llpkg/t/quickjs_demo
  Reason: no LC_RPATH's found
[1]    10313 abort      ./quickjs_demo

@luoliwoshang luoliwoshang changed the title quickjs [wip] quickjs Apr 27, 2025
@luoliwoshang luoliwoshang changed the title [wip] quickjs [wip] quickjs/2024-01-13 Apr 27, 2025
@luoliwoshang luoliwoshang force-pushed the quickjs branch 3 times, most recently from 06d7374 to c8849dc Compare April 27, 2025 11:06
@luoliwoshang luoliwoshang marked this pull request as draft April 27, 2025 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant