Merge pull request #193 from MihailRis/new_lua_funcs
New lua functions moving menus to XML
This commit is contained in:
commit
6447db583b
@ -193,3 +193,13 @@ audio.set_velocity(speakerid: integer, x: number, y: number, z: number)
|
||||
-- also returns 0, if duration is unknown (example: radio)
|
||||
audio.get_duration(speakerid: integer) -> number
|
||||
```
|
||||
|
||||
### Other functions
|
||||
|
||||
```lua
|
||||
-- get current number of alive speakers
|
||||
audio.count_speakers() -> integer
|
||||
|
||||
-- get current number of playing streams
|
||||
audio.count_streams() -> integer
|
||||
```
|
||||
@ -194,3 +194,12 @@ audio.set_velocity(speakerid: integer, x: number, y: number, z: number)
|
||||
audio.get_duration(speakerid: integer) -> number
|
||||
```
|
||||
|
||||
### Другие функции
|
||||
|
||||
```lua
|
||||
-- получить текущее число живых спикеров
|
||||
audio.count_speakers() -> integer
|
||||
|
||||
-- получить текущее число проигрываемых аудио-потоков
|
||||
audio.count_streams() -> integer
|
||||
```
|
||||
|
||||
@ -170,6 +170,14 @@ static std::shared_ptr<UINode> readLabel(UiXmlReader& reader, xml::xmlelement el
|
||||
align_from_string(element->attr("valign").getText(), label->getVerticalAlign())
|
||||
);
|
||||
}
|
||||
if (element->has("supplier")) {
|
||||
auto supplier = scripting::create_wstring_supplier(
|
||||
reader.getEnvironment().getId(),
|
||||
element->attr("supplier").getText(),
|
||||
reader.getFilename()
|
||||
);
|
||||
label->textSupplier(supplier);
|
||||
}
|
||||
return label;
|
||||
}
|
||||
|
||||
|
||||
@ -247,6 +247,14 @@ const char* lua::LuaState::tostring(int idx) {
|
||||
return lua_tostring(L, idx);
|
||||
}
|
||||
|
||||
bool lua::LuaState::isstring(int idx) {
|
||||
return lua_isstring(L, idx);
|
||||
}
|
||||
|
||||
bool lua::LuaState::isfunction(int idx) {
|
||||
return lua_isfunction(L, idx);
|
||||
}
|
||||
|
||||
void lua::LuaState::openlib(const std::string& name, const luaL_Reg* libfuncs, int nup) {
|
||||
lua_newtable(L);
|
||||
luaL_setfuncs(L, libfuncs, nup);
|
||||
|
||||
@ -45,6 +45,8 @@ namespace lua {
|
||||
luaint tointeger(int idx);
|
||||
luanumber tonumber(int idx);
|
||||
const char* tostring(int idx);
|
||||
bool isstring(int idx);
|
||||
bool isfunction(int idx);
|
||||
int call(int argc);
|
||||
int callNoThrow(int argc);
|
||||
int execute(int env, const std::string& src, const std::string& file="<string>");
|
||||
|
||||
@ -391,6 +391,18 @@ static int l_audio_get_velocity(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// @brief audio.count_speakers() -> integer
|
||||
static int l_audio_count_speakers(lua_State* L) {
|
||||
lua_pushinteger(L, audio::count_speakers());
|
||||
return 1;
|
||||
}
|
||||
|
||||
// @brief audio.count_streams() -> integer
|
||||
static int l_audio_count_streams(lua_State* L) {
|
||||
lua_pushinteger(L, audio::count_streams());
|
||||
return 1;
|
||||
}
|
||||
|
||||
const luaL_Reg audiolib [] = {
|
||||
{"play_sound", lua_wrap_errors<l_audio_play_sound>},
|
||||
{"play_sound_2d", lua_wrap_errors<l_audio_play_sound_2d>},
|
||||
@ -414,5 +426,7 @@ const luaL_Reg audiolib [] = {
|
||||
{"get_duration", lua_wrap_errors<l_audio_get_duration>},
|
||||
{"get_position", lua_wrap_errors<l_audio_get_position>},
|
||||
{"get_velocity", lua_wrap_errors<l_audio_get_velocity>},
|
||||
{"count_speakers", lua_wrap_errors<l_audio_count_speakers>},
|
||||
{"count_streams", lua_wrap_errors<l_audio_count_streams>},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
@ -58,7 +58,9 @@ wstringsupplier scripting::create_wstring_supplier(
|
||||
) {
|
||||
return [=](){
|
||||
if (processCallback(env, src, file)) {
|
||||
state->callNoThrow(0);
|
||||
if (state->isfunction(-1)) {
|
||||
state->callNoThrow(0);
|
||||
}
|
||||
auto str = state->tostring(-1); state->pop();
|
||||
return util::str2wstr_utf8(str);
|
||||
}
|
||||
@ -101,7 +103,9 @@ boolsupplier scripting::create_bool_supplier(
|
||||
) {
|
||||
return [=](){
|
||||
if (processCallback(env, src, file)) {
|
||||
state->callNoThrow(0);
|
||||
if (state->isfunction(-1)) {
|
||||
state->callNoThrow(0);
|
||||
}
|
||||
bool x = state->toboolean(-1); state->pop();
|
||||
return x;
|
||||
}
|
||||
@ -129,7 +133,9 @@ doublesupplier scripting::create_number_supplier(
|
||||
) {
|
||||
return [=](){
|
||||
if (processCallback(env, src, file)) {
|
||||
state->callNoThrow(0);
|
||||
if (state->isfunction(-1)) {
|
||||
state->callNoThrow(0);
|
||||
}
|
||||
lua::luanumber x = state->tonumber(-1); state->pop();
|
||||
return x;
|
||||
}
|
||||
@ -159,7 +165,9 @@ vec2supplier scripting::create_vec2_supplier(
|
||||
) {
|
||||
return [=](){
|
||||
if (processCallback(env, src, file)) {
|
||||
state->callNoThrow(0);
|
||||
if (state->isfunction(-1)) {
|
||||
state->callNoThrow(0);
|
||||
}
|
||||
lua::luanumber y = state->tonumber(-1); state->pop();
|
||||
lua::luanumber x = state->tonumber(-1); state->pop();
|
||||
return glm::vec2(x, y);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user