code_fodder
code_fodder

Reputation: 16361

calling love functions in lua

I have installed lua using lua rocks and it works fine. Now I want to use the love libraries to do some graphics within my lua script. But I can't find any documentation on how to link love code to lua code... infact I am still confused as to the difference.

I am under the impression that love is a set of libraries for lua, but love seems to have its own binary for running...meaning it is its own language?

Anyway, here is my sad little attempt at writing a lua script using love:

myluatest.lua:

if "test" == "test" then print("yes") else print("no") end   
love.graphics.print('love test', 400, 300)
print(string.byte("ABCDE", 3, 4))

If I comment out the "love.graphics...." line it works fine. This is how I run the script:

lua myluatest.lua

I feel I need to include love or somthing, I just can't find the syntax :(

Upvotes: 0

Views: 1445

Answers (1)

Kaleb Barrett
Kaleb Barrett

Reputation: 1594

Love is not a library, there is nothing to include. Love is an application written in C++ that is scriptable with Lua. Love exposes its builtin graphics functions (written in C++) to the Lua environment using the C API. It also is the application driver, meaning that you can't run a Love application as you would a regular Lua one. You must fill in the callbacks, mentioned here, then Love will automatically run them.

To make your script work you have to incorporate it into one of the callback functions. If you want some task to run once at the beginning of the application use love.load(), or if you want it to run continuously use love.update(). Only love.draw() can contain calls to love.graphics.draw methods.

function love.draw()
    if "test" == "test" then print("yes") else print("no") end   
    love.graphics.print('love test', 400, 300)
    print(string.byte("ABCDE", 3, 4))
end

Expect a lot of console output, draw() runs continuously.

Upvotes: 2

Related Questions