How to work with ray casts and the returned result

Before i dont write code in LUA so i find out one thing strange in this code:

function update(self, dt)
	local from = go.get_position()
	local to = self.to
	local result = physics.raycast(from, to, { hash("stone") }) -- <4>
	if result then
		draw_line(from, result.position) -- <5>
	else
		draw_line(from, to) -- <6>
	end
end

physics.raycast return a table, not a bolean variable. So why this condition work?
if result then.
result contains a table not a bolean variable, i wanna know it’s a specific of DEFOLD or it’s normal behaviour for LUA?

As you see in the documentation, the function rreturns nil if it didn’t produce a result.

In Lua, if nil then will evaluate to false.

1 Like

if not nil it true?

correct

1 Like