Anyone able to use this with FreeBASIC?

General FreeBASIC programming questions.
Cretin Ho
Posts: 182
Joined: Feb 04, 2021 13:01

Anyone able to use this with FreeBASIC?

Post by Cretin Ho »

fbfrog converted the header nuklear.h fine with only 11 TODOS, after checked I found these TODOS are not important so I could just skip it.

https://github.com/Immediate-Mode-UI/Nuklear

The problem is I don't know how to translate their C example to FreeBASIC to verify if the converted header really works.

You could find the example on their github above.
counting_pine
Site Admin
Posts: 6323
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Re: Anyone able to use this with FreeBASIC?

Post by counting_pine »

Looking at the example in the readme, it doesn't look to me like there's anything there that won't translate to FB..

Code: Select all

/* init gui state */
struct nk_context ctx;
nk_init_fixed(&ctx, calloc(1, MAX_MEMORY), MAX_MEMORY, &font);

enum {EASY, HARD};
static int op = EASY;
static float value = 0.6f;
static int i =  20;

if (nk_begin(&ctx, "Show", nk_rect(50, 50, 220, 220),
    NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_CLOSABLE)) {
    /* fixed widget pixel width */
    nk_layout_row_static(&ctx, 30, 80, 1);
    if (nk_button_label(&ctx, "button")) {
        /* event handling */
    }

    /* fixed widget window ratio width */
    nk_layout_row_dynamic(&ctx, 30, 2);
    if (nk_option_label(&ctx, "easy", op == EASY)) op = EASY;
    if (nk_option_label(&ctx, "hard", op == HARD)) op = HARD;

    /* custom widget pixel width */
    nk_layout_row_begin(&ctx, NK_STATIC, 30, 2);
    {
        nk_layout_row_push(&ctx, 50);
        nk_label(&ctx, "Volume:", NK_TEXT_LEFT);
        nk_layout_row_push(&ctx, 110);
        nk_slider_float(&ctx, 0, &value, 1.0f, 0.1f);
    }
    nk_layout_row_end(&ctx);
}
nk_end(&ctx);
The main thing is probably to declare ctx with something like 'dim ctx as nk_context', and pass '@ctx' to functions. Use 'OR' instead of '|'.
I don't know what MAX_MEMORY should be. Maybe try 100MB '(100 shl 20)' - it should be enough for a simple example without crippling the rest of your system. Or maybe it's part of the header (which isn't #included in the example).
Which parts are you stuck on?
Cretin Ho
Posts: 182
Joined: Feb 04, 2021 13:01

Re: Anyone able to use this with FreeBASIC?

Post by Cretin Ho »

This is my translated code. Not work.

Code: Select all

#include once "nuklear.bi"

/' init gui state '/
dim ctx as nk_contex
nk_init_fixed(@ctx, callocate(1, MAX_MEMORY), MAX_MEMORY, @font)

enum test
EASY
HARD
end enum

dim static as integer op = EASY
dim static as single value = 0.6
dim static as integer i =  20

if nk_begin(@ctx, "Show", nk_rect(50, 50, 220, 220), _
    NK_WINDOW_BORDER or NK_WINDOW_MOVABLE or NK_WINDOW_CLOSABLE) then
    /' fixed widget pixel width '/
    nk_layout_row_static(@ctx, 30, 80, 1)
    if nk_button_label(@ctx, "button") then
        /' event handling '/
    end if

    /' fixed widget window ratio width '/
    nk_layout_row_dynamic(@ctx, 30, 2)
    if nk_option_label(@ctx, "easy", op == EASY) then op = EASY end if
    if nk_option_label(@ctx, "hard", op == HARD) then op = HARD end if

    /' custom widget pixel width '/
    nk_layout_row_begin(@ctx, NK_STATIC, 30, 2)
    nk_layout_row_push(@ctx, 50)
    nk_label(@ctx, "Volume:", NK_TEXT_LEFT)
    nk_layout_row_push(@ctx, 110)
    nk_slider_float(@ctx, 0, @value, 1.0, 0.1)
    nk_layout_row_end(@ctx)
end if

nk_end(@ctx)
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: Anyone able to use this with FreeBASIC?

Post by caseih »

Cretin Ho wrote:Not work.
What doesn't work?
paul doe
Moderator
Posts: 1730
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Anyone able to use this with FreeBASIC?

Post by paul doe »

caseih wrote:What doesn't work?
How about:

Code: Select all

dim static as integer op = EASY
dim static as single value = 0.6
dim static as integer i =  20
@Cretin Ho: remove the dim and declare them like this:

Code: Select all

static as integer op = EASY
static as single value = 0.6
static as integer i =  20
Also, this:

Code: Select all

  if nk_option_label(@ctx, "easy", op == EASY) then op = EASY end if
  if nk_option_label(@ctx, "hard", op == HARD) then op = HARD end if
should be:

Code: Select all

  if nk_option_label(@ctx, "easy", op == EASY) then op = EASY
  if nk_option_label(@ctx, "hard", op == HARD) then op = HARD
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: Anyone able to use this with FreeBASIC?

Post by caseih »

Sure but he could just tell us what the issues were. Cut and paste the compiler error messages. Show what it does when he attempts to run it. Tell us what he's done to identify and debug the issue.
Cretin Ho
Posts: 182
Joined: Feb 04, 2021 13:01

Re: Anyone able to use this with FreeBASIC?

Post by Cretin Ho »

caseih wrote:Sure but he could just tell us what the issues were. Cut and paste the compiler error messages. Show what it does when he attempts to run it. Tell us what he's done to identify and debug the issue.
To be honest I didn't do this because I'm sure it's better if you reproduce the problems with the steps I have taken. Cutting and paste the issues serve nothing. But if you too insisting on it then here you are.

Code: Select all

/home/fellow/Documents/Nuklear/nuklear.bi(337) error 14: Expected identifier, found 'nk_draw_vertex_layout_element' in 'vertex_layout as const nk_draw_vertex_layout_element ptr'
/home/fellow/Documents/Nuklear/nuklear.bi(744) error 71: Incomplete type, before ')' in 'declare function nk_style_push_style_item(byval as nk_context ptr, byval as nk_style_item ptr, byval as nk_style_item) as nk_bool'
/home/fellow/Documents/Nuklear/nuklear.bi(753) error 4: Duplicated definition in 'declare function nk_rgb(byval r as long, byval g as long, byval b as long) as nk_color'
/home/fellow/Documents/Nuklear/nuklear.bi(760) error 4: Duplicated definition in 'declare function nk_rgba(byval r as long, byval g as long, byval b as long, byval a as long) as nk_color'
/home/fellow/Documents/Nuklear/nuklear.bi(831) error 4: Duplicated definition in 'declare function NK_STRTOD alias "nk_strtod"(byval str as const zstring ptr, byval endptr as const zstring ptr ptr) as double'
/home/fellow/Documents/Nuklear/nuklear.bi(840) error 59: Illegal specification, at parameter 3 (glyph) in 'type nk_query_font_glyph_f as sub(byval handle as nk_handle, byval font_height as single, byval glyph as nk_user_font_glyph ptr, byval codepoint as nk_rune, byval next_codepoint as nk_rune)'
/home/fellow/Documents/Nuklear/nuklear.bi(1634) error 4: Duplicated definition in 'declare function nk_style_item_image(byval img as nk_image) as nk_style_item'
/home/fellow/Documents/Nuklear/nuklear.bi(1635) error 4: Duplicated definition in 'declare function nk_style_item_color(byval as nk_color) as nk_style_item'
test.bas(4) error 14: Expected identifier, found 'nk_contex' in 'dim ctx as nk_contex'
test.bas(5) warning 3(2): Passing different pointer types, at parameter 1 of NK_INIT_FIXED()
test.bas(5) error 42: Variable not declared, MAX_MEMORY in 'nk_init_fixed(@ctx, callocate(1, MAX_MEMORY), MAX_MEMORY, @font)'
test.bas(5) error 133: Too many errors, exiting
nuklear.bi is too large to post here in CODE tags. You better download Nuklear itself from https://github.com/Immediate-Mode-UI/Nuklear and use fbfrog on nuklear.h to get the FreeBASIC header. To be able to compile the code yourself, you have to do this anyway, so don't ask me to upload nuklear.bi. But if you still want to I can upload it for you.
Cretin Ho
Posts: 182
Joined: Feb 04, 2021 13:01

Re: Anyone able to use this with FreeBASIC?

Post by Cretin Ho »

paul doe wrote:
caseih wrote:What doesn't work?
How about:

Code: Select all

dim static as integer op = EASY
dim static as single value = 0.6
dim static as integer i =  20
@Cretin Ho: remove the dim and declare them like this:

Code: Select all

static as integer op = EASY
static as single value = 0.6
static as integer i =  20
Also, this:

Code: Select all

  if nk_option_label(@ctx, "easy", op == EASY) then op = EASY end if
  if nk_option_label(@ctx, "hard", op == HARD) then op = HARD end if
should be:

Code: Select all

  if nk_option_label(@ctx, "easy", op == EASY) then op = EASY
  if nk_option_label(@ctx, "hard", op == HARD) then op = HARD
Not work man. I think the generated header by fbfrog is the problem now.

Code: Select all

/home/fellow/Documents/Nuklear/nuklear.bi(337) error 14: Expected identifier, found 'nk_draw_vertex_layout_element' in 'vertex_layout as const nk_draw_vertex_layout_element ptr'
/home/fellow/Documents/Nuklear/nuklear.bi(744) error 71: Incomplete type, before ')' in 'declare function nk_style_push_style_item(byval as nk_context ptr, byval as nk_style_item ptr, byval as nk_style_item) as nk_bool'
/home/fellow/Documents/Nuklear/nuklear.bi(753) error 4: Duplicated definition in 'declare function nk_rgb(byval r as long, byval g as long, byval b as long) as nk_color'
/home/fellow/Documents/Nuklear/nuklear.bi(760) error 4: Duplicated definition in 'declare function nk_rgba(byval r as long, byval g as long, byval b as long, byval a as long) as nk_color'
/home/fellow/Documents/Nuklear/nuklear.bi(831) error 4: Duplicated definition in 'declare function NK_STRTOD alias "nk_strtod"(byval str as const zstring ptr, byval endptr as const zstring ptr ptr) as double'
/home/fellow/Documents/Nuklear/nuklear.bi(840) error 59: Illegal specification, at parameter 3 (glyph) in 'type nk_query_font_glyph_f as sub(byval handle as nk_handle, byval font_height as single, byval glyph as nk_user_font_glyph ptr, byval codepoint as nk_rune, byval next_codepoint as nk_rune)'
/home/fellow/Documents/Nuklear/nuklear.bi(1634) error 4: Duplicated definition in 'declare function nk_style_item_image(byval img as nk_image) as nk_style_item'
/home/fellow/Documents/Nuklear/nuklear.bi(1635) error 4: Duplicated definition in 'declare function nk_style_item_color(byval as nk_color) as nk_style_item'
test.bas(4) error 14: Expected identifier, found 'nk_contex' in 'dim ctx as nk_contex'
test.bas(5) warning 3(2): Passing different pointer types, at parameter 1 of NK_INIT_FIXED()
test.bas(5) error 42: Variable not declared, MAX_MEMORY in 'nk_init_fixed(@ctx, callocate(1, MAX_MEMORY), MAX_MEMORY, @font)'
test.bas(5) error 133: Too many errors, exiting
counting_pine
Site Admin
Posts: 6323
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Re: Anyone able to use this with FreeBASIC?

Post by counting_pine »

Cretin Ho wrote:To be honest I didn't do this because I'm sure it's better if you reproduce the problems with the steps I have taken. Cutting and paste the issues serve nothing.
There are a few advantages in posting the error messages:
- for those who don’t take the time to replicate your steps, the error message might be enough for them to point you towards a possible solution
- for those who do take the time to replicate your steps, it allows them to verify if they’re getting the same error as you

For anyone who wants to help, being told “it doesn’t work” can be a frustrating problem to hear, because it doesn’t give any clues to the solution. And if they try and replicate the problem, they may do things differently somewhere, and end up with it actually working, or experiencing a different problem from you.

For similar reasons, its probably worth posting the header you’ve got. If it translates differently for other people, that may be a clue to the problem.
For what it’s worth, I recommend https://gist.github.com for reliable code sharing.
Cretin Ho
Posts: 182
Joined: Feb 04, 2021 13:01

Re: Anyone able to use this with FreeBASIC?

Post by Cretin Ho »

I think I have to learn more about fbfrog before even try again. The header I generated is problematic. Thanks everyone for help.
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: Anyone able to use this with FreeBASIC?

Post by caseih »

Cretin Ho wrote:To be honest I didn't do this because I'm sure it's better if you reproduce the problems with the steps I have taken. Cutting and paste the issues serve nothing.
Well to be honest, I'm not going to do the debugging work for you, but if I can easily see something you missed by looking at your cut and paste, then that benefits all of us. I note that you neglected to post your converted header files, so there's no easy way for me to reproduce your steps anyway.

As @Counting_pine says, posting the error messages is always the best course of action. Specifically I always recommend the following:
  • Always post a cut and paste of the actual, complete error message
  • Always include the necessary but minimal code to quickly and easily reproduce the issue.
  • When possible make the example code self-contained in as few files as possible, and compile-able if the issue is a runtime error.
  • State the steps you have already taken to identify and mitigate the problem.
Your last post does show the compile errors you're getting, which is good. But without seeing the nuklear.bi file I can't comment further, except to say the problems do seem to originate there.
Cretin Ho
Posts: 182
Joined: Feb 04, 2021 13:01

Re: Anyone able to use this with FreeBASIC?

Post by Cretin Ho »

Man, I think I will never able to debug this further nor could I continue with FreeBASIC. FreeBASIC is a beautiful language that I not yet able to grasp, especially it OOP part. But I have to learn JavaScript to be a freelancer. Goodbye everyone.
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: Anyone able to use this with FreeBASIC?

Post by caseih »

Why do you need to grasp its OOP part? FB is a multi-paradigm language that makes traditional procedural programming quite easy. None of code or issues in this topic have any OOP in them. OOP is simply not always required[1]. FB is a strongly, statically-typed language, similar to C or Pascal, so a lot of programs use user-defined type structures.

I wouldn't expect anyone to quickly master all aspects of FB, so don't feel bad about that! I myself only really know well a subset of all the features of FreeBASIC. I wish you luck in your explorations of Javascript and other languages. Please be patient with yourself. It will be a challenge for you, but worthy of effort!

[1] Javascript is not object-oriented either, although object-oriented variants like TypeScript exist. Javascript is a prototype-based language, with some functional aspects thrown in for good measure. Certainly not my favorite language, but it is a useful one for a freelancer to know.
Cretin Ho
Posts: 182
Joined: Feb 04, 2021 13:01

Re: Anyone able to use this with FreeBASIC?

Post by Cretin Ho »

caseih wrote:Why do you need to grasp its OOP part? FB is a multi-paradigm language that makes traditional procedural programming quite easy. None of code or issues in this topic have any OOP in them. OOP is simply not always required[1]. FB is a strongly, statically-typed language, similar to C or Pascal, so a lot of programs use user-defined type structures.

I wouldn't expect anyone to quickly master all aspects of FB, so don't feel bad about that! I myself only really know well a subset of all the features of FreeBASIC. I wish you luck in your explorations of Javascript and other languages. Please be patient with yourself. It will be a challenge for you, but worthy of effort!

[1] Javascript is not object-oriented either, although object-oriented variants like TypeScript exist. Javascript is a prototype-based language, with some functional aspects thrown in for good measure. Certainly not my favorite language, but it is a useful one for a freelancer to know.
OOP is needed and is the future of FB, IMHO. I have some troubles to grasp FB OOP. Seem I'm too used to the OOP of Java.
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: Anyone able to use this with FreeBASIC?

Post by caseih »

Cretin Ho wrote:OOP is needed and is the future of FB, IMHO. I have some troubles to grasp FB OOP. Seem I'm too used to the OOP of Java.
Why do you say OOP is the future of FB? There are many paradigms for programming that are still valid and necessary. Procedural, functional, asynchronous, etc. OOP is just one and should be used when it is appropriate. If you look around the programming world today you'll find that OOP has largely fallen out of favor, except for some cases where it makes the most sense. FB supports most programming paradigms fairly well. The only one it lacks support for is functional programming. But most classic languages also lack support as functional programming does not always fit well into the classic statically-typed, compiled model.

And there are many forms of OOP. Java's version of OOP is but one form. I must say that Java has ruined generations of programmers into thinking they have to shoe-horn all problems into some kind of class structure. As brilliant as Gosling is, forcing the use of classes to create a namespace was not one of his best moves. Java has also ruined generations of programmers into thinking that there's only one way to do OOP. Getters and setters... ugh.

Having said all this, FB's OOP model is very simple, but effective. What parts of it are you having a hard time grasping?
Post Reply