@@ -227,7 +227,6 @@ static int l_lovrAudioSetReverb(lua_State* L) {
227227static int l_lovrAudioNewSource (lua_State * L ) {
228228 bool decode = false;
229229 bool pitchable = true;
230- bool spatial = false;
231230
232231 if (lua_gettop (L ) >= 2 ) {
233232 luaL_checktype (L , 2 , LUA_TTABLE );
@@ -239,14 +238,10 @@ static int l_lovrAudioNewSource(lua_State* L) {
239238 lua_getfield (L , 2 , "pitchable" );
240239 if (!lua_isnil (L , -1 )) pitchable = lua_toboolean (L , -1 );
241240 lua_pop (L , 1 );
242-
243- lua_getfield (L , 2 , "spatial" );
244- spatial = lua_toboolean (L , -1 );
245- lua_pop (L , 1 );
246241 }
247242
248- Sound * sound = luax_totype (L , 1 , Sound );
249243 AudioStream * stream = luax_totype (L , 1 , AudioStream );
244+ Sound * sound = stream ? lovrAudioStreamGetSound (stream ) : luax_totype (L , 1 , Sound );
250245
251246 if (lua_type (L , 1 ) == LUA_TSTRING || luax_totype (L , 1 , Blob )) {
252247 Blob * blob = luax_readblob (L , 1 , "Source" );
@@ -255,13 +250,18 @@ static int l_lovrAudioNewSource(lua_State* L) {
255250 luax_assert (L , sound );
256251 } else if (sound ) {
257252 lovrRetain (sound );
258- } else if (stream ) {
259- sound = lovrAudioStreamGetSound (stream );
260- lovrRetain (sound );
261253 } else {
262254 return luax_typeerror (L , 1 , "string, Blob, Sound, or AudioStream" );
263255 }
264256
257+ bool spatial = lovrSoundGetChannelCount (sound ) > 2 ;
258+
259+ if (lua_istable (L , 2 )) {
260+ lua_getfield (L , 2 , "spatial" );
261+ if (!lua_isnil (L , -1 )) spatial = lua_toboolean (L , -1 );
262+ lua_pop (L , 1 );
263+ }
264+
265265 Source * source = lovrSourceCreate (sound , pitchable , spatial );
266266 lovrRelease (sound , lovrSoundDestroy );
267267 luax_assert (L , source );
0 commit comments