Work in process [WIP] in development ...
Love2DCS will binding C function and export to dynamic library to provide function to C# code. C# will use System.Runtime.InteropServices
to interop with native libraries. : https://www.mono-project.com/docs/advanced/pinvoke/
a. tool
- Window 7/8/8.1/10
Viual Studio 2013
orVisual Studio 2015
orVisaul Studio 2017
https://visualstudio.microsoft.com- Cmake https://cmake.org/
- mercurial https://www.mercurial-scm.org/
b. build C Part :
- Follow the instructions at the megasource repository page to build LÖVE 11.0+. if you use Visual studio 2017, just setup v140 toolset : https://blogs.msdn.microsoft.com/vcblog/2017/11/02/visual-studio-build-tools-now-include-the-vs2017-and-vs2015-msvc-toolsets/, and build megasource with VC++ 2015.3 v14.00 (v140) toolset : https://stackoverflow.com/questions/47154454/cmake-how-to-specify-vs2015-3-toolset-with-vs2017-installed. or
cmake -G "Visual Studio 15" -T v140
- clone repository
git clone https://github.com/endlesstravel/Love2dCS
- Add files
c_api_src/wrap_love_dll.cpp
andc_api_src/wrap_love_dll.h
to your LÖVE project inliblove
- follow example in
wrap_love_dll.cpp
andwrap_love_dll.h
to modify / add more function - this step will generate
love.dll
/lua51.dll
/mpg123
/OpenAL32.dll
/SDL2.dll
, this is what we need.
c. build C# part :
- create C# console application with visual studio
- add all code
csharp_src/*.cs
to your C# project. - set workspace to
love.dll
locate directory or just copylove.dll
/lua51.dll
/mpg123
/OpenAL32.dll
/SDL2.dll
to yourxxxxx.exe
locate directory.
a. tool
- ubuntu 14.4 (china mirrors source: https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/)
b. build C Part :
- clone repository:
git clone https://github.com/love2d/love
- to the root of the love srource:
cd love
- then change CMake file from
set(LOVE_SRC_MODULE_LOVE
src/modules/love/love.cpp
src/modules/love/love.h
)
to
set(LOVE_SRC_MODULE_LOVE
src/modules/love/love.cpp
src/modules/love/love.h
src/modules/love/wrap_love_dll.cpp
src/modules/love/wrap_love_dll.h
)
- download
wrap_love_dll.cpp
andwrap_love_dll.h
to/src/modules/love
cd ./src/modules/love
wget -o src/modules/love/wrap_love_dll.cpp https://github.com/endlesstravel/Love2dCS/raw/master/c_api_src/wrap_love_dll.cpp
wget -o src/modules/love/wrap_love_dll.h https://github.com/endlesstravel/Love2dCS/raw/master/c_api_src/wrap_love_dll.h
- Follow the instructions at the Building LÖVE to build
LÖVE
- library will finded at
src\.libs\love-11.1.so
, this is what we need. - Question about Linux binaries size : call 'strip -s' on them, to remove (mostly) debug information.
strip -s love-11.1.so
c. build C# Part :
- install monodevelop : https://www.monodevelop.com/download/#fndtn-download-lin-ubuntu
- open monodevelop, create C# Console Application, add all
*.cs
code undercsharp_src
folder to your C# project. - copy
love-11.1.so
to your build path and rename toliblove.so
- build & run
sed '/set\s*(\s*LOVE_SRC_MODULE_LOVE/a\src/modules/love/wrap_love_dll.cpp\nsrc/modules/love/wrap_love_dll.h' love/CMakeLists.txt > love/CMakeLists.txt.tmp
mv love/CMakeLists.txt love/CMakeLists.txt.old
mv love/CMakeLists.txt.tmp love/CMakeLists.txt
wget -o love/src/modules/love/wrap_love_dll.cpp https://github.com/endlesstravel/Love2dCS/raw/master/c_api_src/wrap_love_dll.cpp
wget -o love/src/modules/love/wrap_love_dll.h https://github.com/endlesstravel/Love2dCS/raw/master/c_api_src/wrap_love_dll.h
ls love/src/modules/love
Love.Graphics.Print / Love.Graphics.Printf / Love.Graphics can receive 0-terminated byte array (https://docs.microsoft.com/en-us/cpp/cpp/string-and-character-literals-cpp?view=vs-2017#narrow-string-literals) to represent end of string input. for example :
var bytes = new bytes[] {65, 66, 67, 0}; // "ABC"
Love.Graphics.Print(bytes, 0, 0); // print "ABC" at position (0, 0)