Skip to content

Latest commit

 

History

History
100 lines (79 loc) · 4.46 KB

develop.md

File metadata and controls

100 lines (79 loc) · 4.46 KB

Work in process [WIP] in development ...

The way of Love2DCS work

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/

Setup develop environment

1. Windows

a. tool

b. build C Part :

liblove-src

  • follow example in wrap_love_dll.cpp and wrap_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 copy love.dll / lua51.dll / mpg123 / OpenAL32.dll / SDL2.dll to your xxxxx.exe locate directory.

2. Ubuntu

a. tool

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 and wrap_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
strip -s love-11.1.so

c. build C# Part :

docker build

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

Code Convention

UTF8

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)

Resource manage