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,313
Trophies
3
XP
12,110
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
  • No one is chatting at the moment.
  • K3Nv2 @ K3Nv2:
    why
  • Xdqwerty @ Xdqwerty:
    @K3Nv2, it's not funny
  • K3Nv2 @ K3Nv2:
    ok
  • BigOnYa @ BigOnYa:
    Wut?
  • K3Nv2 @ K3Nv2:
    That's not funny
    +2
  • Psionic Roshambo @ Psionic Roshambo:
    So two cannibals where eating a clown and one says to the other. Hey does this taste funny to you?
    +2
  • K3Nv2 @ K3Nv2:
    What do you call a slow car? Retired
    +1
  • Psionic Roshambo @ Psionic Roshambo:
    Did you hear about the police car that someone stole the wheels off of? The police are working tirelessly to find the thieves.
    +2
  • K3Nv2 @ K3Nv2:
    A firefighter got arrested for assault his main claim was what I was told he was on fire
    +2
  • BigOnYa @ BigOnYa:
    What do you call a hooker with a runny nose? Full
    +2
  • Psionic Roshambo @ Psionic Roshambo:
    What do you tell a woman with two black eyes? Nothing you already told her twice!
  • K3Nv2 @ K3Nv2:
    Diddy also works
  • K3Nv2 @ K3Nv2:
    A scientist heard the word batman so he put a naked lady in a cage with a bat
  • Psionic Roshambo @ Psionic Roshambo:
    Chuck Norris won a staring contest, with the sun.
  • K3Nv2 @ K3Nv2:
    A vampires favorite thing to do is moon you
  • BigOnYa @ BigOnYa:
    What's the difference between an airplane, and Ken's mom? Not everyone has been in an airplane.
  • K3Nv2 @ K3Nv2:
    What's the difference between @BigOnYa and his wife? Nothing both want to bone me
    +3
  • RedColoredStars @ RedColoredStars:
    How much wood could a wood chuck chuck if a wood chuck could chuck norris
    +1
  • BakerMan @ BakerMan:
    how do i know? you're a guy, and he wants to bone every guy on this site (maybe, idk)
    +1
  • K3Nv2 @ K3Nv2:
    He wants to bone anything with a dick
    +1
  • Xdqwerty @ Xdqwerty:
    Good night
    +1
  • BigOnYa @ BigOnYa:
    Nighty night, big day tomorrow. Congrats.
    K3Nv2 @ K3Nv2: https://www.instagram.com/reel/C7iLZ35NrQt/?igsh=MWd2Z3U0dmNlMmNxcw==