lgi-devs / lgi-devs/lgi

Handling foreign structure pointers returned from a function call

Open
#109 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Lua
Stars
491
Forks
81
PR merge metrics
No merged PRs in 30d

Description

First of all, thank you for starting this awesome project!

I'm currently working on a service using WebKitGTK+ (It's WebKit1 interface) and I faced with the problem of JavaScriptCore GTK bindings which simply do not exist. As there is gir file describing two foreign structures - JavaScriptCore.GlobalContext and JavaScriptCore.Value - I decided to try to use LuaJIT's FFI to operate with this structures directly.

So, I'm calling web_view:get_main_frame():get_global_context() to get JSGlobalContextRef but the returning pointer value is slightly different from the value returned by direct FFI call ffi.C.webkit_web_frame_get_global_context(web_view:get_main_frame()._native). It looks like JavaScriptCore.GlobalContext is boxed but I'm unable to find a proper way to unbox it. I've already tried some GValue magic but it seems I'm doing it wrong. Here is what I always get:

cdata<struct OpaqueJSContext *>: 0x7fb0dc1df9b0
lgi.rec 0x7ffc9c0d1bf0:JavaScriptCore.GlobalContext

What is the recommended way to handle foreign pointers in this case?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the mismatch between get_global_context() and ffi.C.webkit_web_frame_get_global_context(web_view:get_main_frame()._native) using the WebKitGTK WebKit1 calls described in the issue. Inspect how lgi represents JavaScriptCore.GlobalContext and JavaScriptCore.Value foreign structures; done means establishing and documenting a supported way to handle the returned pointers.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, lua
Domain
tooling
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.