nngn
Loading...
Searching...
No Matches
platform.h
Go to the documentation of this file.
1#ifndef NNGN_OS_PLATFORM_H
2#define NNGN_OS_PLATFORM_H
3
4#include <csignal>
5#include <filesystem>
6#include <span>
7
8#include "config.h"
9
10#if defined(_WIN64) || defined(__x86_64__)
11 #define NNGN_PLATFORM_64BIT
12#else
13 #define NNGN_PLATFORM_32BIT
14#endif
15
16#ifdef __EMSCRIPTEN__
17 #define NNGN_PLATFORM_EMSCRIPTEN
18 #undef HAVE_TERMIOS_H
19 #undef NNGN_PLATFORM_HAS_SOCKETS
20#endif
21
22namespace nngn {
23
24struct Platform {
25#ifndef NDEBUG
26 static constexpr bool debug = true;
27#else
28 static constexpr bool debug = false;
29#endif
30#ifdef NNGN_PLATFORM_32BIT
31 static constexpr bool m32 = true, m64 = false;
32#elif defined(NNGN_PLATFORM_64BIT)
33 static constexpr bool m32 = false, m64 = true;
34#endif
35#ifdef NNGN_PLATFORM_EMSCRIPTEN
36 static constexpr bool emscripten = true;
37#else
38 static constexpr bool emscripten = false;
39#endif
40#ifdef NNGN_LUA_USE_ALLOC
41 static constexpr bool lua_use_alloc = true;
42#else
43 static constexpr bool lua_use_alloc = false;
44#endif
45#ifdef NNGN_PLATFORM_HAS_LIBPNG
46 static constexpr bool has_libpng = true;
47#else
48 static constexpr bool has_libpng = false;
49#endif
50#ifdef NNGN_PLATFORM_HAS_SOCKETS
51 static constexpr bool has_sockets = true;
52#else
53 static constexpr bool has_sockets = false;
54#endif
55#ifdef NNGN_PLATFORM_HAS_VMA
56 static constexpr bool has_vma = true;
57#else
58 static constexpr bool has_vma = false;
59#endif
60#ifdef SIGPIPE
61 static constexpr int sig_pipe = SIGPIPE;
62#else
63 static constexpr int sig_pipe = 0;
64#endif
65 static std::span<const char *const> argv;
66 static std::filesystem::path src_dir;
67 static bool init(int argc, const char *const *argv);
68 static void setenv(const char *name, const char *value);
69 static bool set_non_blocking(FILE *f);
70 static int loop(int (*loop)(void));
71};
72
73}
74
75#endif
Definition: debug.h:45
name
Definition: old_man.lua:1
function f()) end
Definition: platform.h:24
static constexpr bool emscripten
Definition: platform.h:38
static constexpr bool lua_use_alloc
Definition: platform.h:43
static constexpr bool has_libpng
Definition: platform.h:46
static void setenv(const char *name, const char *value)
Definition: platform.cpp:30
static bool set_non_blocking(FILE *f)
Definition: platform.cpp:58
static constexpr bool m32
Definition: platform.h:31
static constexpr bool has_sockets
Definition: platform.h:53
static constexpr bool m64
Definition: platform.h:31
static int loop(int(*loop)(void))
Definition: platform.cpp:73
static std::filesystem::path src_dir
Definition: platform.h:66
static constexpr bool debug
Definition: platform.h:26
static constexpr bool has_vma
Definition: platform.h:58
static constexpr int sig_pipe
Definition: platform.h:63
static bool init(int argc, const char *const *argv)
Definition: platform.cpp:42
static std::span< const char *const > argv
Definition: platform.h:65