Page 1 of 1

How to call Löve functions from regular lua?

Posted: Thu Sep 25, 2014 7:54 pm
by Tosse
Is it possible to "wrap" Löve? I wan't to run regular lua files with lua interpreter and invoke Löve inside functions.
For example: I have test.lua with:
...

Code: Select all

function displayText(text,x,y)
  love.graphics.print(text,x,y)
end
...
Then run it with:
lua test.lua

Re: How to call Löve functions from regular lua?

Posted: Fri Sep 26, 2014 2:04 am
by hardcrawler
Lua is an embedded language. That means that its intent is to be embedded in other programs for the purpose of scripting them. Usually, this is a C/C++ application.

When you run "lua" from the command line, you are running a very small executable C program that has minimal abilities. You pretty much only get what is built into the Lua standard libraries. 95% of this is internal to the Lua language itself. You only get a very minimal ability to interact with the "outside world." Essentially you get some basic ability to open files etc.

Love is a C/C++ application that glues together SDL, libpng, openal, mpg123, and various other libraries. Love supports scripting via Lua. From Lua, the C/C++ functionality of Love is all accessed via the global Lua table "love" This "love" table only exists for your script because you are running your script from the Love C/C++ application, and it has explicitly exported this functionality into the Lua namespace.

Therefore, it is impossible for you to access any love functionality when executing a .lua script using the "lua" command line tool.

Re: How to call Löve functions from regular lua?

Posted: Fri Sep 26, 2014 6:36 am
by bartbes
liblove is meant for exactly this purpose, it's just not that... user-friendly at the moment. It is still much easier to run from love, if only because it deals with both the setup and giving you a functional main loop.