From 5250cb90406693163763a214af95f670e0e3a4e0 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 5 Oct 2018 05:02:49 +0200 Subject: Add cross compilation (mingw-w64 x86_64) Currently only cross compiling from linux64 to win64 works. Need to test cross compilation more, currently the cross compilation uses same profile as GCC, is that correct? --- examples/hello_lua/.gitignore | 5 +++++ examples/hello_lua/hello.lua | 1 + examples/hello_lua/project.conf | 8 ++++++++ examples/hello_lua/src/main.cpp | 31 ++++++++++++++++++++++++++++++ examples/hello_lua_mingw_w64/.gitignore | 5 +++++ examples/hello_lua_mingw_w64/README.md | 1 + examples/hello_lua_mingw_w64/hello.lua | 1 + examples/hello_lua_mingw_w64/project.conf | 8 ++++++++ examples/hello_lua_mingw_w64/run.sh | 8 ++++++++ examples/hello_lua_mingw_w64/src/main.cpp | 32 +++++++++++++++++++++++++++++++ 10 files changed, 100 insertions(+) create mode 100644 examples/hello_lua/.gitignore create mode 100644 examples/hello_lua/hello.lua create mode 100644 examples/hello_lua/project.conf create mode 100644 examples/hello_lua/src/main.cpp create mode 100644 examples/hello_lua_mingw_w64/.gitignore create mode 100644 examples/hello_lua_mingw_w64/README.md create mode 100644 examples/hello_lua_mingw_w64/hello.lua create mode 100644 examples/hello_lua_mingw_w64/project.conf create mode 100755 examples/hello_lua_mingw_w64/run.sh create mode 100644 examples/hello_lua_mingw_w64/src/main.cpp (limited to 'examples') diff --git a/examples/hello_lua/.gitignore b/examples/hello_lua/.gitignore new file mode 100644 index 0000000..636c6b9 --- /dev/null +++ b/examples/hello_lua/.gitignore @@ -0,0 +1,5 @@ +# Compiled sibs files +sibs-build/ +compile_commands.json +tests/sibs-build/ +tests/compile_commands.json diff --git a/examples/hello_lua/hello.lua b/examples/hello_lua/hello.lua new file mode 100644 index 0000000..4601856 --- /dev/null +++ b/examples/hello_lua/hello.lua @@ -0,0 +1 @@ +print("inside lua!") diff --git a/examples/hello_lua/project.conf b/examples/hello_lua/project.conf new file mode 100644 index 0000000..e416497 --- /dev/null +++ b/examples/hello_lua/project.conf @@ -0,0 +1,8 @@ +[package] +name = "hello_lua" +type = "executable" +version = "0.1.0" +platforms = ["any"] + +[dependencies] +lua51 = "5.1.5" diff --git a/examples/hello_lua/src/main.cpp b/examples/hello_lua/src/main.cpp new file mode 100644 index 0000000..57f9194 --- /dev/null +++ b/examples/hello_lua/src/main.cpp @@ -0,0 +1,31 @@ +#include +extern "C" { +#include +#include +#include +} +int main(int argc, char *argv[]) { + // Open lua + lua_State *L = lua_open(); + + // Load the libraries + luaL_openlibs(L); + + // Execution of a lua string + luaL_dostring(L, "print \"Yo dude\""); + + // Load a string and then execute it. + luaL_loadstring(L, "io.write(\"I'm here too\\n\")"); + lua_pcall(L, 0, LUA_MULTRET, 0); + + // Load from a file and then execute + if (luaL_loadfile(L, "hello.lua") == 0) { + // File loaded call it + lua_pcall(L, 0, LUA_MULTRET, 0); + } + + // Close lua + lua_close (L); + + return 0; +} diff --git a/examples/hello_lua_mingw_w64/.gitignore b/examples/hello_lua_mingw_w64/.gitignore new file mode 100644 index 0000000..636c6b9 --- /dev/null +++ b/examples/hello_lua_mingw_w64/.gitignore @@ -0,0 +1,5 @@ +# Compiled sibs files +sibs-build/ +compile_commands.json +tests/sibs-build/ +tests/compile_commands.json diff --git a/examples/hello_lua_mingw_w64/README.md b/examples/hello_lua_mingw_w64/README.md new file mode 100644 index 0000000..524476d --- /dev/null +++ b/examples/hello_lua_mingw_w64/README.md @@ -0,0 +1 @@ +This is an example of using system lua5.1 package (pkg-config). diff --git a/examples/hello_lua_mingw_w64/hello.lua b/examples/hello_lua_mingw_w64/hello.lua new file mode 100644 index 0000000..4601856 --- /dev/null +++ b/examples/hello_lua_mingw_w64/hello.lua @@ -0,0 +1 @@ +print("inside lua!") diff --git a/examples/hello_lua_mingw_w64/project.conf b/examples/hello_lua_mingw_w64/project.conf new file mode 100644 index 0000000..b568575 --- /dev/null +++ b/examples/hello_lua_mingw_w64/project.conf @@ -0,0 +1,8 @@ +[package] +name = "hello_lua" +type = "executable" +version = "0.1.0" +platforms = ["any"] + +[dependencies] +lua5.1 = "5.1.5" diff --git a/examples/hello_lua_mingw_w64/run.sh b/examples/hello_lua_mingw_w64/run.sh new file mode 100755 index 0000000..0f23a37 --- /dev/null +++ b/examples/hello_lua_mingw_w64/run.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +set -e + +script_path=`readlink -f $0` +script_dir=`dirname $script_path` +cd "$script_dir" +sibs build --platform win64 && ./sibs-build/debug/hello_lua.exe diff --git a/examples/hello_lua_mingw_w64/src/main.cpp b/examples/hello_lua_mingw_w64/src/main.cpp new file mode 100644 index 0000000..1486b98 --- /dev/null +++ b/examples/hello_lua_mingw_w64/src/main.cpp @@ -0,0 +1,32 @@ +// Example taken from http://lua-users.org/lists/lua-l/2010-06/msg00153.html +#include +extern "C" { +#include +#include +#include +} +int main(int argc, char *argv[]) { + // Open lua + lua_State *L = lua_open(); + + // Load the libraries + luaL_openlibs(L); + + // Execution of a lua string + luaL_dostring(L, "print \"Yo dude\""); + + // Load a string and then execute it. + luaL_loadstring(L, "io.write(\"I'm here too\\n\")"); + lua_pcall(L, 0, LUA_MULTRET, 0); + + // Load from a file and then execute + if (luaL_loadfile(L, "hello.lua") == 0) { + // File loaded call it + lua_pcall(L, 0, LUA_MULTRET, 0); + } + + // Close lua + lua_close (L); + + return 0; +} -- cgit v1.2.3