terroo / luasfml

Binding SFML to LUA . This project is a fork of the original project: https://github.com/Canadadry/luaSFML

Home Page:https://github.com/terroo/luasfml

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Lua SFML Binding

Binding SFML to LUA

Lua SFML


Description

LuaSFML is a lua binding of SFML, which let's you use SFML in your lua script.

This project is a fork of the original project which has been stalled for over 9 years and has compilation and other issues.


Dependencies

Example on Ubuntu

sudo apt update
sudo apt install build-essential g++ make cmake lua5.1 liblua5.1-0 liblua5.1-0-dev

Building and Instalation

git clone https://github.com/terroo/luasfml
cd luasfml
mkdir build && cd build
cmake ..
make
sudo make install

Got error ?

/usr/bin/ld: could not find -llua: No such file or directory
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/luasfml.dir/build.make:801: luasfml] Erro 1
make[1]: *** [CMakeFiles/Makefile2:84: CMakeFiles/luasfml.dir/all] Erro 2
make: *** [Makefile:136: all] Erro 2

To fix it on Ubuntu, run the following command:

sudo ln -s /usr/lib/x86_64-linux-gnu/liblua5.1.so /usr/lib/x86_64-linux-gnu/liblua.so

For other systems find /usr/lib* -name 'liblua5.1.so' where the file is and create a symlink in the same directory. Or run the command below:

sudo ln -s $(find /usr/lib* -name 'liblua5.1.so') \
           $(find /usr/lib* -name 'liblua5.1.so' | sed 's/5.1//g')

And then run make again:

make
sudo make install

Basic Example

Comming soon Wiki, In the meantime you can learn by the Examples/Demos .

If you already know SFML with C++ and also know Lua, you will adapt easily. If you want to contribute to the documentation, feel free.

File main.lua

window = sfRenderWindow.new(sfVideoMode.new(800,600,32),"Lua SFML Basic Example",sfWindowStyle.Default);

clearColor = sfColor.new(0,0,0);
colorWhite = sfColor.new(255, 255, 255)

font = sfFont.new()
font:loadFromFile("path/to/font.ttf")

message = sfText.new("This is Lua SFML!",font,40);
message:setPosition( 200, 250);
message:setColor(colorWhite)

while window:isOpen() do
  event = sfEvent.new();
  while window:pollEvent(event) do
    if(event:type() == sfEventType.Closed) then window:close(); 
    end
  end
  window:clear(clearColor);
  window:draw(message);
  window:display();
end

To run use the luasfml command and the name of the main file of your project:

luasfml main.lua

This example is available in the assets directory of that repository. To run:

cd assets/
luasfml main.lua

Possible output:

Basic Example Lua SFML


Similar Projects


Uninstall

git clone https://github.com/terroo/luasfml
cd luasfml
mkdir build && cd build
cmake ..
sudo make uninstall

About

Binding SFML to LUA . This project is a fork of the original project: https://github.com/Canadadry/luaSFML

https://github.com/terroo/luasfml

License:MIT License


Languages

Language:C++ 69.0%Language:C 29.9%Language:CMake 0.6%Language:Lua 0.4%