The concept behind this is interesting: https://github.com/webview/webview
Anyone interested to convert webview.h to webview.bi? Please give if a try. It has an example for plain C but the header itself I think is C++.
Anyone able to convert this to FreeBASIC?
Re: Anyone able to convert this to FreeBASIC?
Working header for FreeBASIC:
webview_c.bi
A test program:
test.bas
Compile fine, but failed to link since there is no shared library on Linux:
webview_c.bi
Code: Select all
#pragma once
extern "C"
type webview_t as any ptr
declare function webview_create(byval debug as long, byval window as any ptr) as webview_t
declare sub webview_destroy(byval w as webview_t)
declare sub webview_run(byval w as webview_t)
declare sub webview_terminate(byval w as webview_t)
declare sub webview_dispatch(byval w as webview_t, byval fn as sub(byval w as webview_t, byval arg as any ptr), byval arg as any ptr)
declare function webview_get_window(byval w as webview_t) as any ptr
declare sub webview_set_title(byval w as webview_t, byval title as const zstring ptr)
const WEBVIEW_HINT_NONE = 0
const WEBVIEW_HINT_MIN = 1
const WEBVIEW_HINT_MAX = 2
const WEBVIEW_HINT_FIXED = 3
declare sub webview_set_size(byval w as webview_t, byval width as long, byval height as long, byval hints as long)
declare sub webview_navigate(byval w as webview_t, byval url as const zstring ptr)
declare sub webview_init(byval w as webview_t, byval js as const zstring ptr)
declare sub webview_eval(byval w as webview_t, byval js as const zstring ptr)
declare sub webview_bind(byval w as webview_t, byval name as const zstring ptr, byval fn as sub(byval seq as const zstring ptr, byval req as const zstring ptr, byval arg as any ptr), byval arg as any ptr)
declare sub webview_return(byval w as webview_t, byval seq as const zstring ptr, byval status as long, byval result as const zstring ptr)
end extern
test.bas
Code: Select all
#include once "webview_c.bi"
#ifndef NULL
const NULL as any ptr = 0
#endif
dim w as webview_t
w = webview_create(0, NULL)
webview_set_title(w, "Webview Example")
webview_set_size(w, 480, 320, WEBVIEW_HINT_NONE)
webview_navigate(w, "https://en.m.wikipedia.org/wiki/Main_Page")
webview_run(w)
webview_destroy(w)
Code: Select all
$ fbc test.bas
test.o: In function `main':
test.c:(.text+0x3f): undefined reference to `webview_create'
test.c:(.text+0x5e): undefined reference to `webview_set_title'
test.c:(.text+0x79): undefined reference to `webview_set_size'
test.c:(.text+0x8c): undefined reference to `webview_navigate'
test.c:(.text+0x98): undefined reference to `webview_run'
test.c:(.text+0xa4): undefined reference to `webview_destroy'
Re: Anyone able to convert this to FreeBASIC?
There's no library here. webview_create() is defined in webview.h It's a C wrapper over a C++ call. In essence you have to compile that part with C++ to make an object file that you can use from FB. Should be relatively easy to do that:
Then use the resulting webview.o file when you're compiling your FB code. Although you'll need to manually tell FB to link in the shared libraries from webkit2gtk and its dependencies. Probably like this:
It would be nice if FBC would support GCC-style library linker flags then you could use pkg-config directly in the linking step.
Code: Select all
g++ -c webview.cc `pkg-config --cflags webkit2gtk-4.0`
Code: Select all
/opt/FreeBASIC/bin/fbc test.bas webview.o -l webkit2gtk-4.0 -l gtk-3 -l gdk-3 -l pangocairo-1.0 -l pango-1.0 -l harfbuzz -l atk-1.0 -l cairo-gobject -l cairo -l gdk_pixbuf-2.0 -l soup-2.4 -l gio-2.0 -l javascriptcoregtk-4.0 -l gobject-2.0 -l glib-2.0 -l stdc++
Re: Anyone able to convert this to FreeBASIC?
Moved to General Forum