How to call Löve functions from regular lua?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Tosse
Prole
Posts: 3
Joined: Thu Sep 25, 2014 5:08 pm

How to call Löve functions from regular lua?

Post 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
User avatar
hardcrawler
Prole
Posts: 12
Joined: Fri Jun 27, 2014 11:31 pm

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

Post 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.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

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

Post 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.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 7 guests