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.
-
whiteland92
- Prole
- Posts: 12
- Joined: Fri Jul 04, 2014 1:30 am
Post
by whiteland92 » Thu Mar 10, 2016 7:21 pm
if you are using "type(image)" it return "userdata", would it be possible change it to "image" ?
and is it possible to load images from a url, without saving it to your pc?
Code: Select all
local http = require"socket.http"
http.request{
url = "http://i.imgur.com/YGmjfbG.jpg",
sink = function(chunk, err)
if chunk then
f = love.filesystem.newFile("cat.png")
f:open('a')
f:write(chunk)
f:close()
end
return 1
end
}
error(type(love.graphics.newImage("cat.png")),2,love.filesystem.remove("cat.png"))
-
Nixola
- Inner party member
- Posts: 1949
- Joined: Tue Dec 06, 2011 7:11 pm
- Location: Italy
Post
by Nixola » Thu Mar 10, 2016 7:53 pm
You can use [wiki] love.filesystem.newFileData[/wiki] for the latter.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
-
zorg
- Party member
- Posts: 3043
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
-
Contact:
Post
by zorg » Thu Mar 10, 2016 8:07 pm
For the former, using [wiki]Object:type[/wiki] instead of lua's type function would be the solution.
Me and my stuff
True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
-
whiteland92
- Prole
- Posts: 12
- Joined: Fri Jul 04, 2014 1:30 am
Post
by whiteland92 » Thu Mar 10, 2016 8:14 pm
well that was fast and easier then i though it would be. thank you so much. both of you
works like a charm
Code: Select all
local http = require"socket.http"
local data = love.graphics.newImage( love.filesystem.newFileData( http.request("http://i.imgur.com/YGmjfbG.jpg") , "" , "file" ) )
error(data:type(),2)
--> Error: Image
-
T-Bone
- Inner party member
- Posts: 1492
- Joined: Thu Jun 09, 2011 9:03 am
Post
by T-Bone » Sat Mar 12, 2016 1:25 pm
One thing that would be useful however, was if Lua's error messages would say the Löve type name it was expecting. So if you did
Code: Select all
love.graphics.draw("cat.png", 10, 10)
You'd get an error saying "expected Drawable, got string" instead of the current "expected Userdata, got string".
Maybe that'd be very hard to implement?
-
slime
- Solid Snayke
- Posts: 2918
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
-
Contact:
Post
by slime » Sat Mar 12, 2016 1:36 pm
It already does that:
Code: Select all
love.graphics.draw("cat.png", 10, 10)
LÖVE wrote:Error: main.lua:1: bad argument #1 to 'draw' (Drawable expected, got string)
-
whiteland92
- Prole
- Posts: 12
- Joined: Fri Jul 04, 2014 1:30 am
Post
by whiteland92 » Sat Mar 12, 2016 6:36 pm
one problem i found is that if you are using Löve ":type()" on string,number,table.... it crashes the program.
example
Code: Select all
local text = "Hello World!"
local textType = text:type()
-- this will fail and "blue screen" --> Main.lua 2: attempt to call method 'type' (a nil value)
-
zorg
- Party member
- Posts: 3043
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
-
Contact:
Post
by zorg » Sat Mar 12, 2016 7:14 pm
That's to be expected since löve doesn't modify the metatables for basic types (if they have/support one anyway), so it does not add type to them as a callable function.
Me and my stuff
True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
-
Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
-
Contact:
Post
by Robin » Mon Mar 21, 2016 2:25 pm
You can use this function for that:
Code: Select all
function realType(obj)
return obj.type and obj:type() or type(obj)
end
Users browsing this forum: No registered users and 34 guests