added ag:🔉:{set,get}Volume() Lua interfaces

git-svn-id: svn://anubis/anaglym/trunk@295 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
Josh Holtrop 2010-07-27 15:09:36 +00:00
parent 9cdf2a4243
commit 957552e5b9
2 changed files with 37 additions and 0 deletions

35
ag.cc
View File

@ -327,6 +327,10 @@ namespace ag
lua_setfield(L, -2, "loop"); lua_setfield(L, -2, "loop");
lua_pushcfunction(L, sound::loopForever); lua_pushcfunction(L, sound::loopForever);
lua_setfield(L, -2, "loopForever"); lua_setfield(L, -2, "loopForever");
lua_pushcfunction(L, sound::getVolume);
lua_setfield(L, -2, "getVolume");
lua_pushcfunction(L, sound::setVolume);
lua_setfield(L, -2, "setVolume");
} }
static void createLuaAMotor(lua_State * L, int id) static void createLuaAMotor(lua_State * L, int id)
@ -1701,5 +1705,36 @@ namespace ag
} }
return 0; return 0;
} }
int getVolume(lua_State * L)
{
int argc = lua_gettop(L);
if (argc == 1 && lua_istable(L, 1))
{
refptr<AV::Sound> snd = getSound(L, 1);
if (!snd.isNull())
{
float v = snd->getVolume();
lua_pushnumber(L, v);
return 1;
}
}
return 0;
}
int setVolume(lua_State * L)
{
int argc = lua_gettop(L);
if (argc == 2 && lua_istable(L, 1) && lua_isnumber(L, 2))
{
refptr<AV::Sound> snd = getSound(L, 1);
if (!snd.isNull())
{
float volume = lua_tonumber(L, 2);
snd->setVolume(volume);
}
}
return 0;
}
} }
} }

2
ag.h
View File

@ -114,6 +114,8 @@ namespace ag
int stop(lua_State * L); int stop(lua_State * L);
int loop(lua_State * L); int loop(lua_State * L);
int loopForever(lua_State * L); int loopForever(lua_State * L);
int getVolume(lua_State * L);
int setVolume(lua_State * L);
} }
} }