How interested would the community be in a modern C++ partial rewrite/partial wrapper of libnx

noneuclideanmotion

Member
OP
Newcomer
Joined
Nov 1, 2022
Messages
13
Trophies
0
Age
22
XP
72
Country
United Kingdom
After using it for a little bit, it feels very old fashioned when writing with it using C++. This is not the fault of the developers, of course, it is written in C. I also noticed there were a lot of bugs and things that didn't work properly and the biggest thing: the lack of clear documentation! I spent just under a week trying to figure out how it handles fonts (turns out, it requires a literal 1-1 binary representation of the glyphs and that's all it can handle).

I'm very comfortable with C++, so I've been thinking about making my own library based off of libnx for modern C++, with object oriented, function concepts and as much clear documentation as I can cram into it, as I find that a lot easier to work with compared to endless functions which I barely know the function of (ironic). I've already started it, mainly for myself, but I'm just doing a litmus test to see if anybody else would be interested.

I've started with a console API, here is an example program

Code:
#import <lnxw/console.hpp>

int main() {
    lnxw::console default_console;             //no argument creates a default console
   
    //Alternative way of making a console
    lnxw::console::properties p;
    p.text_color = lnxw::color::BLUE;
    p.background_color = lnxw::color::RED;  //RGB values work as well
    lnxw::console other_console(p);
    //Obviously you could also use curly braces to define the properties within the constructor
    //properties have the following attibutes (more to come!)
    /* this is the definition with the default values
    struct properties {
            uint16_t        cursor_x           = 0;
            uint16_t        cursor_y           = 0;
            uint16_t        width              = 80;
            uint16_t        height             = 45;
            uint8_t         tab_width          = 5;
            uint8_t         text_size          = 16;
            color            text_color         = color::WHITE;
            color            background_color   = color::BLACK;
            console::font   font               = console::font::default_font;
        };
    */
   
    default_console.print<std::string>("Hello World!\n"); //will print white text on black background
    other_console.print<std::string>("Hello World too!\n");
    // You don't need the <> as it will automatically determine the type
   
    std::cout << "Hello world using cout";
    //Cout will be directed to the last used console I'm planning to add the following syntax:
    std::cout << console_to_print_to << "words";
    std::cout << nxlink << "print to pc screen";
   
    return 0;
}

Without all the comments, here would be a simple hello world program:

Code:
import <lnxw/console.hpp>;
import <iostream>;
int main() {
    lnxw::console::default::print("Hello world!");
    //or
    lnxw::console default;
    default.print("Hello World");
   
    //or or
    lnxw::console default;
    std::cout << "Hello world!"
}

Just one or two lines!

This is compared to libnx's hello world which is this:

Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <switch.h>

// Main program entrypoint
int main(int argc, char* argv[])
{
    consoleInit(NULL);
    padConfigureInput(1, HidNpadStyleSet_NpadStandard);
    printf("Hello World!\n");
    while (appletMainLoop())
    {
        consoleUpdate(NULL);
    }
    consoleExit(NULL);
    return 0;
}

My console class is just a wrapper right now, but I'm planning to just remake it completely since the libnx has quite a few bugs in it's console.h and I'm already using a custom version of the library to even be able to allow you to change the console at all. (In the official libnx, you are not able to change the colour, text size, etc due to what I think is a bug)

Any anyway, would anybody be interested?
 
  • Like
Reactions: white5pirit

white5pirit

New Member
Newbie
Joined
Oct 24, 2021
Messages
1
Trophies
0
Age
24
XP
36
Country
United Kingdom
After using it for a little bit, it feels very old fashioned when writing with it using C++. This is not the fault of the developers, of course, it is written in C. I also noticed there were a lot of bugs and things that didn't work properly and the biggest thing: the lack of clear documentation! I spent just under a week trying to figure out how it handles fonts (turns out, it requires a literal 1-1 binary representation of the glyphs and that's all it can handle).

I'm very comfortable with C++, so I've been thinking about making my own library based off of libnx for modern C++, with object oriented, function concepts and as much clear documentation as I can cram into it, as I find that a lot easier to work with compared to endless functions which I barely know the function of (ironic). I've already started it, mainly for myself, but I'm just doing a litmus test to see if anybody else would be interested.

I've started with a console API, here is an example program

Code:
#import <lnxw/console.hpp>

int main() {
    lnxw::console default_console;             //no argument creates a default console
  
    //Alternative way of making a console
    lnxw::console::properties p;
    p.text_color = lnxw::color::BLUE;
    p.background_color = lnxw::color::RED;  //RGB values work as well
    lnxw::console other_console(p);
    //Obviously you could also use curly braces to define the properties within the constructor
    //properties have the following attibutes (more to come!)
    /* this is the definition with the default values
    struct properties {
            uint16_t        cursor_x           = 0;
            uint16_t        cursor_y           = 0;
            uint16_t        width              = 80;
            uint16_t        height             = 45;
            uint8_t         tab_width          = 5;
            uint8_t         text_size          = 16;
            color            text_color         = color::WHITE;
            color            background_color   = color::BLACK;
            console::font   font               = console::font::default_font;
        };
    */
  
    default_console.print<std::string>("Hello World!\n"); //will print white text on black background
    other_console.print<std::string>("Hello World too!\n");
    // You don't need the <> as it will automatically determine the type
  
    std::cout << "Hello world using cout";
    //Cout will be directed to the last used console I'm planning to add the following syntax:
    std::cout << console_to_print_to << "words";
    std::cout << nxlink << "print to pc screen";
  
    return 0;
}

Without all the comments, here would be a simple hello world program:

Code:
import <lnxw/console.hpp>;
import <iostream>;
int main() {
    lnxw::console::default::print("Hello world!");
    //or
    lnxw::console default;
    default.print("Hello World");
  
    //or or
    lnxw::console default;
    std::cout << "Hello world!"
}

Just one or two lines!

This is compared to libnx's hello world which is this:

Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <switch.h>

// Main program entrypoint
int main(int argc, char* argv[])
{
    consoleInit(NULL);
    padConfigureInput(1, HidNpadStyleSet_NpadStandard);
    printf("Hello World!\n");
    while (appletMainLoop())
    {
        consoleUpdate(NULL);
    }
    consoleExit(NULL);
    return 0;
}

My console class is just a wrapper right now, but I'm planning to just remake it completely since the libnx has quite a few bugs in it's console.h and I'm already using a custom version of the library to even be able to allow you to change the console at all. (In the official libnx, you are not able to change the colour, text size, etc due to what I think is a bug)

Any anyway, would anybody be interested?
That would be super nice 👀
 

masagrator

The patches guy
Developer
Joined
Oct 14, 2018
Messages
6,284
Trophies
3
XP
12,057
Country
Poland
Guy seems to stop coming here.
Beside his example is wrong. It's not in loop, so it would exit immediately before anybody would see what was printed in console.
I was curious how it would handle exiting from loop.
 
Last edited by masagrator,

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • BigOnYa @ BigOnYa:
    True, everything almost double nowadays
  • K3Nv2 @ K3Nv2:
    But I could go to Aldis and get a cookie pie for like $4
  • BigOnYa @ BigOnYa:
    Or use your new cooking pan and make some, don't mind the Old leftover foods mixed in.
  • K3Nv2 @ K3Nv2:
    Just eat plain flour around cops
  • BigOnYa @ BigOnYa:
    thats Gluten abuse, they would shoot you
  • K3Nv2 @ K3Nv2:
    Depends on the color chart
  • K3Nv2 @ K3Nv2:
    Wheat flour has a lower chance at survival
  • Veho @ Veho:
    Isn't wheat flour the whitest of the white?
  • Veho @ Veho:
    Rye would get shot at sight.
    +1
  • K3Nv2 @ K3Nv2:
    Depends
    img_5941-1.jpeg
    everyone mixing their flour now days
  • Veho @ Veho:
    That's whole wheat, right? Because all purpose flour is also made from wheat.
  • K3Nv2 @ K3Nv2:
    I'm not a flour expert I just snort it
  • BigOnYa @ BigOnYa:
    There also is black rice flour, and its really black colored
  • Veho @ Veho:
    Bruh that's gray.
  • K3Nv2 @ K3Nv2:
    That's ancientboi color
    +1
  • Veho @ Veho:
    You need to add some activated charcoal.
    +1
  • BigOnYa @ BigOnYa:
    I've seen some that are dark dark, my wifey uses it sometimes in her bs recipes
  • Veho @ Veho:
    Cool.
  • SylverReZ @ SylverReZ:
    @BigOnYa, Seems like your wifey likes hers black. :creep:
  • Veho @ Veho:
    "BS" stands for "Bowel Scraping" because that's what whole grain does.
    +1
  • K3Nv2 @ K3Nv2:
    I've been eating honey wheat bread scrumptious
  • K3Nv2 @ K3Nv2:
    https://a.co/d/9xDkOHc lol living on the edge
    K3Nv2 @ K3Nv2: https://a.co/d/9xDkOHc lol living on the edge