Giter VIP home page Giter VIP logo

Comments (4)

brentp avatar brentp commented on May 18, 2024 1

You've set up bindLib correctly, but you called hts_open with 1 arg instead of 2. Since Cyber currently has function overloading by number of params, it say's it's missing a symbol. I'll make the error message more descriptive.

Oh, wow. Thanks for noticing this. Indeed it's working now.

from cyber.

fubark avatar fubark commented on May 18, 2024

This hasn't been implemented yet but I did check that it's possible with libtcc. It would look something like this in Cyber:

import os 'os'

lib = os.bindLib('./libfoo.so', [
    os.CFunc{ sym: 'getBitStruct', args: [#uint], ret: bitStruct }
    os.CStruct{ fields: [os.CuintBits(1), os.CuintBits(31)], type: bitStruct }
])

object bitStruct:
  flag number
  other number

s = lib.getBitStruct(22)
print s.flag
print s.other

from cyber.

brentp avatar brentp commented on May 18, 2024

I see. Thanks for the response.
For that example, I also don't mind bitshifting myself. I do have a related question. I was just trying out wrapping htslib. The first function is hts_open with this signature:

htsFile *hts_open(const char *fn, const char *mode);

where htsFile is:

typedef struct htsFile {
    uint32_t is_bin:1, is_write:1, is_be:1, is_cram:1, is_bgzf:1, dummy:27;
    int64_t lineno;
    kstring_t line;
    char *fn, *fn_aux;
    union {
        BGZF *bgzf;
        struct cram_fd *cram;
        struct hFILE *hfile;
    } fp;
    void *state;  // format specific state information
    htsFormat format;
    hts_idx_t *idx;
    const char *fnidx;
    struct sam_hdr_t *bam_header;
    struct hts_filter_t *filter;
} htsFile;

so I'd prefer not to specify that in cyber. In fact it can be completely opaque.
I tried this:

import os 'os'

hts = os.bindLib('libhts.so', [
    os.CFunc{ sym: 'hts_open', args: [#charPtrZ, #charPtrZ], ret: #ptr}
])
print hts

h = hts.hts_open("../htslib/test/range.bam")
print h

but I see:

BindLib53175d61490b23df
panic: Missing method symbol `hts_open` from receiver of type `BindLib53175d61490b23df`.

/home/brentp/src/cyber/bam.cy:8:5 main:
h = hts.hts_open("../htslib/test/range.bam")
    ^

Is there a way to do this without writing a separate shared lib containing a wrapper function that returns a void *?

from cyber.

fubark avatar fubark commented on May 18, 2024

You've set up bindLib correctly, but you called hts_open with 1 arg instead of 2. Since Cyber currently has function overloading by number of params, it say's it's missing a symbol. I'll make the error message more descriptive.

Is there a way to do this without writing a separate shared lib containing a wrapper function that returns a void *

That's the intended purpose of #ptr, I think it will be renamed to #voidPtr in the near future.

from cyber.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.