Skip to content

Commit 1c6409a

Browse files
hello world
1 parent 312acae commit 1c6409a

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,8 @@ modules.order
5050
Module.symvers
5151
Mkfile.old
5252
dkms.conf
53+
54+
# Switch stuff
55+
build/
56+
*.nacp
57+
*.nro

Makefile

+3-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
5959
ASFLAGS := -g $(ARCH)
6060
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
6161

62-
LIBS := -lnx
62+
LIBS := -lpython3.8m -lm -lnx
6363

6464
#---------------------------------------------------------------------------------
6565
# list of directories containing libraries, this must be the top level containing
@@ -109,7 +109,8 @@ export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES)))
109109

110110
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
111111
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
112-
-I$(CURDIR)/$(BUILD)
112+
-I$(CURDIR)/$(BUILD) \
113+
-I$(PORTLIBS)/include/python3.8m
113114

114115
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
115116

source/main.c

+18-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
// Include the main libnx system header, for Switch development
77
#include <switch.h>
88

9+
// Include the main cpython header
10+
#include <Python.h>
11+
912
// Main program entrypoint
1013
int main(int argc, char* argv[])
1114
{
@@ -16,8 +19,21 @@ int main(int argc, char* argv[])
1619
// take a look at the graphics/opengl set of examples, which uses EGL instead.
1720
consoleInit(NULL);
1821

19-
// Other initialization goes here. As a demonstration, we print hello world.
20-
printf("Hello World!\n");
22+
Py_NoSiteFlag = 1;
23+
Py_IgnoreEnvironmentFlag = 1;
24+
Py_NoUserSiteDirectory = 1;
25+
26+
/* Look for python libraries in /lib/python3.X/ */
27+
Py_SetPythonHome(L"/");
28+
29+
Py_Initialize();
30+
31+
printf("Python %s on %s\n", Py_GetVersion(), Py_GetPlatform());
32+
33+
/* Execute some python code!!! */
34+
PyRun_SimpleString("print('Hello python world! Press + to exit.')");
35+
36+
Py_Finalize();
2137

2238
// Main loop
2339
while (appletMainLoop())

0 commit comments

Comments
 (0)