Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: LuaSFML  (Read 12636 times)

0 Members and 3 Guests are viewing this topic.

Diego

  • Newbie
  • *
  • Posts: 6
    • View Profile
LuaSFML
« on: November 12, 2007, 04:38:31 am »
I'm working on a module for Lua using SFML.

Here some simple Lua code example http://lua.pastey.net/76987

Code: [Select]

-- Requires the window module
require("LuaSFML.window")

--[[
  Create the window:
-- Width              = 800
-- Height             = 600
-- BPP                = 32
-- Caption            = "Title"
-- Style              = sfWindowFixed
-- Antialiasing level = 0
]]
Window = sfWindowCreate(800, 600, 32, "Title", sfWindowFixed, 0)

-- Start main loop
IsRunning = true

while (IsRunning) do

-- Manage events
Event = sfEventCreate()
while (sfWindowGetEvent(Window, Event)) do
-- Close event
if (sfEventType(Event) == sfEventClose) then
-- Terminate
IsRunning = false ;
end
end

-- Display the window
sfWindowDisplay(Window)
end


I don't know if someone is already working on a wrapper for lua, let me know.

Regards.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
LuaSFML
« Reply #1 on: November 12, 2007, 04:50:07 am »
That's a great idea :)

However, just a suggestion, Lua supports some kind of OO syntax (using tables) ; I think it would be better and cleaner to use it, don't you think ?
Laurent Gomila - SFML developer

Diego

  • Newbie
  • *
  • Posts: 6
    • View Profile
LuaSFML
« Reply #2 on: November 12, 2007, 04:55:47 am »
Thank you, i will consider it.

Regards.

Lord Delvin

  • Jr. Member
  • **
  • Posts: 68
    • ICQ Messenger - 166781460
    • View Profile
LuaSFML
« Reply #3 on: November 12, 2007, 09:27:26 am »
This might be usefull for a OO syntax, as syntax with : is a bit confusing.

Code: [Select]

--This is derived from Salmaso Raffaele by Timm Felden
--the origin and the license can be found at http://thread.gmane.org/gmane.comp.lang.lua.general/12344/focus=12344

function Class(super, typename)
    -- create a new class description
    local class = {}
    -- set the superclass (for object/function inheritance)
    setmetatable(class, {
        __index = super,
        __call = function(this, ...) --a call of Class is similar to C++'s new class(...)
            local tmp = {}
            setmetatable(tmp, class)
            if this.new then
            local err = this.new(tmp, ...); -- non-nil return values are exceptions and will be printed
            if err then
            print(err);
            return nil;
            end
            end
            return tmp
        end
    })
    class.__type = typename
    if super and super.__tostring then --einige Metamethods müssen scheinbar von Hand geerbt werden
    class.__tostring = super.__tostring
    end
    class.__index = function(table, key)
        local r = class[key]
        if type(r) == 'function' then
            local f = function(...) return r(table, ...) end
            table[key] = f
            return f
        else
      table[key] = r
            return r
        end
    end
    return class
end


usage:
Code: [Select]

A = class(nil, "A");
A.new = function(this, name) this.name = name end
A.__add = function(this, that) return A(this.name .. that.name) end
A.print = function(this) print(this.name) end

B = class(A, "B")
B.print = function(this) print(this.name .. " is a B!") end

hope it works for you and is usefull:)

Diego

  • Newbie
  • *
  • Posts: 6
    • View Profile
LuaSFML
« Reply #4 on: November 12, 2007, 08:00:39 pm »
Thanks everybody.
This is the new syntax using OO. http://lua.pastey.net/77016
Code: [Select]

-- Create the window
Window = sf.Window:New(800, 600, 32, "Title", sf.Window.Fixed, 0) ;

-- Main loop
IsRunning = true
while (IsRunning) do
-- Manage events
Event = sf.Event:New()
while (Window:GetEvent(Event)) do
-- If close event
if (Event.Type == sf.Event.Close) then
-- Terminate
IsRunning = false ;
end
end

-- Display the window
Window:Display()
end


Opinions? Thanks.

Regards.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
LuaSFML
« Reply #5 on: November 13, 2007, 02:18:53 am »
That was fast ;)

It looks very good now. Have you converted every SFML package ?
Laurent Gomila - SFML developer

Diego

  • Newbie
  • *
  • Posts: 6
    • View Profile
LuaSFML
« Reply #6 on: November 13, 2007, 03:55:44 am »
Thank you.

Quote

Have you converted every SFML package ?

No, i'm just finishing the Window package.

Diego.-

Adrien Poupin

  • Guest
LuaSFML
« Reply #7 on: January 25, 2008, 05:30:09 pm »
Hello,
I've just seen that thread in fact, and I was wondering something... What do you think about the LuaBind wrapper for C++, which has a richer OO approach ?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
LuaSFML
« Reply #8 on: January 25, 2008, 05:47:05 pm »
LuaBind is for dynamically binding C++ classes and functions so that they are available when your C++ program runs a Lua script.

Here we want to create (compile, or whatever) a module for Lua, which can be used without a C++ program running behind it.

By the way, is there any update on this binding ? It looked promising.
Laurent Gomila - SFML developer

Adrien Poupin

  • Guest
LuaSFML
« Reply #9 on: January 25, 2008, 05:48:02 pm »
Ah ok, I didn't catch ;)

But that's fine !