The Battle for Wesnoth  1.15.12+dev
lua_audio.cpp
Go to the documentation of this file.
1 /*
2 Copyright (C) 2017-2018 by the Battle for Wesnoth Project https://www.wesnoth.org/
3 
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY.
10 
11 See the COPYING file for more details.
12 */
13 
14 #include "lua_audio.hpp"
15 
16 #include "log.hpp"
17 #include "lua/lua.h"
18 #include "lua/lauxlib.h"
19 #include "scripting/lua_common.hpp"
20 #include "scripting/push_check.hpp"
21 #include "sound.hpp"
22 #include "sound_music_track.hpp"
23 #include "preferences/general.hpp"
24 #include "resources.hpp"
25 #include "soundsource.hpp"
26 #include <set>
27 
28 static lg::log_domain log_audio("audio");
29 #define DBG_AUDIO LOG_STREAM(debug, log_audio)
30 #define LOG_AUDIO LOG_STREAM(info, log_audio)
31 #define ERR_AUDIO LOG_STREAM(err, log_audio)
32 
33 static const char* Track = "music track";
34 static const char* Source = "sound source";
35 
37  std::shared_ptr<sound::music_track> track;
38 public:
39  explicit lua_music_track(int i) : track(sound::get_track(i)) {}
40  explicit lua_music_track(std::shared_ptr<sound::music_track> new_track) : track(new_track) {}
41  bool valid() const {
42  return track && track->valid();
43  }
45  return *track;
46  }
47  const sound::music_track& operator*() const {
48  return *track;
49  }
50  std::shared_ptr<sound::music_track> operator->() {
51  return track;
52  }
53  std::shared_ptr<const sound::music_track> operator->() const {
54  return track;
55  }
56 };
57 
59  lua_music_track* trk = new(L) lua_music_track(i);
61  return trk;
62 }
63 
64 static lua_music_track* push_track(lua_State* L, std::shared_ptr<sound::music_track> new_track) {
65  lua_music_track* trk = new(L) lua_music_track(new_track);
67  return trk;
68 }
69 
71  return static_cast<lua_music_track*>(luaL_checkudata(L, i, Track));
72 }
73 
76 public:
77  explicit lua_sound_source(const soundsource::sourcespec& spec) : spec(spec) {}
80  return spec;
81  }
83  return spec;
84  }
86  return &spec;
87  }
89  return &spec;
90  }
91 };
92 
94  lua_sound_source* src = new(L) lua_sound_source(spec);
96  return *src;
97 }
98 
100  return *static_cast<lua_sound_source*>(luaL_checkudata(L, i, Source));
101 }
102 
103 /**
104  * Destroys a lua_music_track object before it is collected (__gc metamethod).
105  */
107 {
108  lua_music_track* u = get_track(L, 1);
109  u->lua_music_track::~lua_music_track();
110  return 0;
111 }
112 
113 static int impl_music_get(lua_State* L) {
114  if(lua_isnumber(L, 2)) {
115  push_track(L, lua_tointeger(L, 2) - 1);
116  return 1;
117  }
118  const char* m = luaL_checkstring(L, 2);
119 
120  if(strcmp(m, "current") == 0) {
122  return 1;
123  }
124 
125  if(strcmp(m, "previous") == 0) {
127  return 1;
128  }
129 
130  if(strcmp(m, "current_i") == 0) {
131  auto current_index = sound::get_current_track_index();
132  if(current_index) {
133  lua_pushinteger(L, *current_index + 1);
134  } else {
135  lua_pushnil(L);
136  }
137  return 1;
138  }
139  if(strcmp(m, "all") == 0) {
140  config playlist;
142  const auto& range = playlist.child_range("music");
143  std::vector<config> tracks(range.begin(), range.end());
144  lua_push(L, tracks);
145  return 1;
146  }
147  // This calculation reverses the one used in [volume] to get back the relative volume level.
148  // (Which is the same calculation that's duplicated in impl_music_set.)
150  return luaW_getmetafield(L, 1, m);
151 }
152 
153 static int impl_music_set(lua_State* L) {
154  if(lua_isnumber(L, 2)) {
155  unsigned int i = lua_tointeger(L, 2) - 1;
156  config cfg;
157  if(lua_isnil(L, 3)) {
158  if(i < sound::get_num_tracks()) {
160  }
161  } else if(luaW_toconfig(L, 3, cfg)) {
162  // Don't allow play_once=yes
163  if(cfg["play_once"]) {
164  return luaL_argerror(L, 3, "For play_once, use wesnoth.music_list.play instead");
165  }
166  if(i < sound::get_num_tracks()) {
168  } else {
169  // Remove the track at that index and add the new one in its place
170  // It's a little inefficient though...
172  sound::play_music_config(cfg, false, i);
173  }
174  } else {
175  lua_music_track& track = *get_track(L, 3);
176  if(i < sound::get_num_tracks()) {
177  sound::set_track(i, track.operator->());
178  } else {
179  track->write(cfg, true);
181  }
182  }
183  return 0;
184  }
185  const char* m = luaL_checkstring(L, 2);
187  modify_int_attrib_check_range("current_i", sound::play_track(value - 1), 1, static_cast<int>(sound::get_num_tracks()));
188  return 0;
189 }
190 
191 static int impl_music_len(lua_State* L) {
193  return 1;
194 }
195 
196 static int intf_music_play(lua_State* L) {
198  return 0;
199 }
200 
202  std::size_t n = sound::get_num_tracks();
203  if(n > 0) {
205  }
206  return 0;
207 }
208 
209 static int intf_music_add(lua_State* L) {
210  int index = -1;
211  if(lua_isinteger(L, 1)) {
212  index = lua_tointeger(L, 1);
213  lua_remove(L, 1);
214  }
215  config cfg = config {
216  "name", luaL_checkstring(L, 1),
217  "append", true,
218  };
219  bool found_ms_before = false, found_ms_after = false, found_imm = false;
220  for(int i = 2; i <= lua_gettop(L); i++) {
221  if(lua_isboolean(L, i)) {
222  if(found_imm) {
223  return luaL_argerror(L, i, "only one boolean argument may be passed");
224  } else {
225  cfg["immediate"] = luaW_toboolean(L, i);
226  }
227  } else if(lua_isnumber(L, i)) {
228  if(found_ms_after) {
229  return luaL_argerror(L, i, "only two integer arguments may be passed");
230  } else if(found_ms_before) {
231  cfg["ms_after"] = lua_tointeger(L, i);
232  found_ms_after = true;
233  } else {
234  cfg["ms_before"] = lua_tointeger(L, i);
235  found_ms_before = true;
236  }
237  } else {
238  return luaL_argerror(L, i, "unrecognized argument");
239  }
240  }
241  sound::play_music_config(cfg, false, index);
242  return 0;
243 }
244 
247  return 0;
248 }
249 
250 static int intf_music_remove(lua_State* L) {
251  // Use a non-standard comparator to ensure iteration in descending order
252  std::set<int, std::greater<int>> to_remove;
253  for(int i = 1; i <= lua_gettop(L); i++) {
254  to_remove.insert(luaL_checkinteger(L, i));
255  }
256  for(int i : to_remove) {
258  }
259  return 0;
260 }
261 
264  return 0;
265 }
266 
267 static int impl_track_get(lua_State* L) {
269  if(track == nullptr) {
270  return luaL_error(L, "Error: Attempted to access an invalid music track.\n");
271  }
272  const char* m = luaL_checkstring(L, 2);
273  return_bool_attrib("valid", track->valid());
274  if(!track->valid()) {
275  return luaL_error(L, "Tried to access member of track that is no longer valid.");
276  }
277  return_bool_attrib("append", (*track)->append());
278  return_bool_attrib("shuffle", (*track)->shuffle());
279  return_bool_attrib("immediate", (*track)->immediate());
280  return_bool_attrib("once", (*track)->play_once());
281  return_int_attrib("ms_before", (*track)->ms_before());
282  return_int_attrib("ms_after", (*track)->ms_after());
283  return_string_attrib("name", (*track)->id());
284  return_string_attrib("title", (*track)->title());
285 
286  return_cfg_attrib("__cfg",
287  cfg["append"]=(*track)->append();
288  cfg["shuffle"]=(*track)->shuffle();
289  cfg["immediate"]=(*track)->immediate();
290  cfg["once"]=(*track)->play_once();
291  cfg["ms_before"]=(*track)->ms_before();
292  cfg["ms_after"]=(*track)->ms_after();
293  cfg["name"]=(*track)->id();
294  cfg["title"]=(*track)->title());
295 
296  return luaW_getmetafield(L, 1, m);
297 }
298 
299 static int impl_track_set(lua_State* L) {
301  if(track == nullptr || !track->valid()) {
302  return luaL_error(L, "Error: Attempted to access an invalid music track.\n");
303  }
304  const char* m = luaL_checkstring(L, 2);
305  modify_bool_attrib("shuffle", (*track)->set_shuffle(value));
306  modify_bool_attrib("once", (*track)->set_play_once(value));
307  modify_int_attrib("ms_before", (*track)->set_ms_before(value));
308  modify_int_attrib("ms_after", (*track)->set_ms_after(value));
309  modify_string_attrib("title", (*track)->set_title(value));
310  return 0;
311 }
312 
313 static int impl_track_eq(lua_State* L) {
314  lua_music_track* a = get_track(L, 1);
315  lua_music_track* b = get_track(L, 2);
316  if(!a || !b) {
317  // This implies that one argument is not a music track, though I suspect this is dead code...?
318  // Does Lua ever call this if the arguments are not of the same type?
319  lua_pushboolean(L, false);
320  return 1;
321  }
322  if(!a->valid() && !b->valid()) {
323  lua_pushboolean(L, true);
324  return 1;
325  }
326  if(a->valid() && b->valid()) {
327  lua_music_track& lhs = *a;
328  lua_music_track& rhs = *b;
329  lua_pushboolean(L, lhs->id() == rhs->id() && lhs->shuffle() == rhs->shuffle() && lhs->play_once() == rhs->play_once() && lhs->ms_before() == rhs->ms_before() && lhs->ms_after() == rhs->ms_after());
330  return 1;
331  }
332  lua_pushboolean(L, false);
333  return 1;
334 }
335 
336 /**
337  * Get an existing sound source
338  * Key: The sound source ID
339  */
340 static int impl_sndsrc_get(lua_State* L) {
342  return 0;
343  }
344  std::string id = luaL_checkstring(L, 2);
346  return 0;
347  }
349  return 1;
350 }
351 
352 /**
353  * Adds or removes a sound source by its ID
354  * Key: sound source ID
355  * Value: Table containing keyword arguments, existing sound source userdata, or nil to delete
356  */
357 static int impl_sndsrc_set(lua_State* L) {
359  return 0;
360  }
361  std::string id = luaL_checkstring(L, 2);
362  config cfg;
363  if(lua_isnil(L, 3)) {
365  } else if(luaW_toconfig(L, 3, cfg)) {
366  cfg["id"] = id;
367  soundsource::sourcespec spec(cfg);
370  } else {
371  auto& src = get_source(L, 3);
374  }
375  return 0;
376 }
378 {
379  lua_sound_source& u = get_source(L, 1);
380  u.lua_sound_source::~lua_sound_source();
381  return 0;
382 }
383 
384 static int impl_source_get(lua_State* L) {
385  lua_sound_source& src = get_source(L, 1);
386  const char* m = luaL_checkstring(L, 2);
387  return_string_attrib("id", src->id());
389  return_int_attrib("delay", src->minimum_delay());
390  return_int_attrib("chance", src->chance());
391  return_int_attrib("loop", src->loops());
392  return_int_attrib("range", src->full_range());
393  return_int_attrib("fade_range", src->fade_range());
394  return_bool_attrib("check_fogged", src->check_fogged());
395  return_bool_attrib("check_shrouded", src->check_shrouded());
396  return_cfg_attrib("__cfg", src->write(cfg));
397 
398  if(strcmp(m, "locations") == 0) {
399  const auto& locs = src->get_locations();
400  lua_createtable(L, locs.size(), 0);
401  for(const auto& loc : locs) {
402  luaW_pushlocation(L, loc);
403  lua_rawseti(L, -1, lua_rawlen(L, -2) + 1);
404  }
405  }
406 
407  return luaW_getmetafield(L, 1, m);
408 }
409 
410 static int impl_source_set(lua_State* L) {
411  lua_sound_source& src = get_source(L, 1);
412  const char* m = luaL_checkstring(L, 2);
413  modify_int_attrib("delay", src->set_minimum_delay(value));
414  modify_int_attrib("chance", src->set_chance(value));
415  modify_int_attrib("loop", src->set_loops(value));
416  modify_int_attrib("range", src->set_full_range(value));
417  modify_int_attrib("fade_range", src->set_fade_range(value));
418  modify_bool_attrib("check_fogged", src->set_check_fogged(value));
419  modify_bool_attrib("check_shrouded", src->set_check_shrouded(value));
420 
421  if(strcmp(m, "sounds") == 0) {
422  std::string files;
423  if(lua_istable(L, 3)) {
424  files = utils::join(lua_check<std::vector<std::string>>(L, 3));
425  } else {
426  files = luaL_checkstring(L, 3);
427  }
428  src->set_files(files);
429  }
430 
431  if(strcmp(m, "locations") == 0) {
432  std::vector<map_location> locs;
433  locs.resize(1);
434  if(luaW_tolocation(L, 3, locs[0])) {
435 
436  } else {
437  locs.clear();
438  for(lua_pushnil(L); lua_next(L, 3); lua_pop(L, 1)) {
439  locs.push_back(luaW_checklocation(L, -1));
440  }
441  }
442  src->set_locations(locs);
443  }
444 
445  // Now apply the change
448  return 0;
449 }
450 
451 static int impl_source_eq(lua_State* L) {
452  lua_sound_source& a = get_source(L, 1);
453  lua_sound_source& b = get_source(L, 2);
454  if(a->id() != b->id()) {
455  lua_pushboolean(L, false);
456  return 1;
457  }
458  lua_pushboolean(L,
459  a->files() == b->files() &&
460  a->minimum_delay() == b->minimum_delay() &&
461  a->chance() == b->chance() &&
462  a->loops() == b->loops() &&
463  a->full_range() == b->full_range() &&
464  a->fade_range() == b->fade_range() &&
465  a->check_fogged() == b->check_fogged() &&
466  a->check_shrouded() == b->check_shrouded() &&
467  std::set<map_location>(a->get_locations().begin(), a->get_locations().end()) == std::set<map_location>(b->get_locations().begin(), b->get_locations().end())
468  );
469  return 1;
470 }
471 
472 /**
473  * Gets the current sound volume
474  * - Return: Current volume
475  */
476 static int impl_audio_get(lua_State* L)
477 {
478  std::string m = luaL_checkstring(L, 2);
479  if(m != "volume") return 0;
480  int vol = preferences::sound_volume();
481  lua_pushnumber(L, sound::get_sound_volume() * 100.0 / vol);
482  return 1;
483 }
484 
485 /**
486  * Sets the current sound volume
487  * - Arg: New volume to set
488  */
489 static int impl_audio_set(lua_State* L)
490 {
491  std::string m = luaL_checkstring(L, 2);
492  if(m != "volume") {
493  lua_rawset(L, 1);
494  return 0;
495  }
496  int vol = preferences::sound_volume();
497  lua_pushnumber(L, sound::get_sound_volume() * 100.0 / vol);
498  float rel = lua_tonumber(L, 2);
499  if(rel < 0.0f || rel > 100.0f) {
500  return luaL_argerror(L, 1, "volume must be in range 0..100");
501  }
502  vol = static_cast<int>(rel*vol / 100.0f);
504  return 0;
505 }
506 
507 namespace lua_audio {
508  std::string register_table(lua_State* L) {
509  // Metatable to enable the volume attribute
510  luaW_getglobal(L, "wesnoth", "audio");
511  lua_createtable(L, 0, 2);
512  static luaL_Reg vol_callbacks[] {
513  { "__index", impl_audio_get },
514  { "__newindex", impl_audio_set },
515  { nullptr, nullptr },
516  };
517  luaL_setfuncs(L, vol_callbacks, 0);
518  lua_setmetatable(L, -2);
519 
520  // The music playlist metatable
521  lua_newuserdatauv(L, 0, 0);
522  lua_createtable(L, 0, 10);
523  static luaL_Reg pl_callbacks[] {
524  { "__index", impl_music_get },
525  { "__newindex", impl_music_set },
526  { "__len", impl_music_len },
527  { "play", intf_music_play },
528  { "add", intf_music_add },
529  { "clear", intf_music_clear },
530  { "remove", intf_music_remove },
531  { "next", intf_music_next },
532  { "force_refresh", intf_music_commit },
533  { nullptr, nullptr },
534  };
535  luaL_setfuncs(L, pl_callbacks, 0);
536  lua_pushstring(L, "music playlist");
537  lua_setfield(L, -2, "__metatable");
538  lua_setmetatable(L, -2);
539  lua_setfield(L, -2, "music_list");
540 
541  // The sound source map metatable
542  lua_newuserdatauv(L, 0, 0);
543  lua_createtable(L, 0, 3);
544  static luaL_Reg slm_callbacks[] {
545  { "__index", impl_sndsrc_get },
546  { "__newindex", impl_sndsrc_set },
547  { nullptr, nullptr },
548  };
549  luaL_setfuncs(L, slm_callbacks, 0);
550  lua_pushstring(L, "sound source map");
551  lua_setfield(L, -2, "__metatable");
552  lua_setmetatable(L, -2);
553  lua_setfield(L, -2, "sources");
554  lua_pop(L, 1);
555 
556  // The music track metatable
558  static luaL_Reg track_callbacks[] {
559  {"__gc", impl_track_collect},
560  { "__index", impl_track_get },
561  { "__newindex", impl_track_set },
562  { "__eq", impl_track_eq },
563  { nullptr, nullptr },
564  };
565  luaL_setfuncs(L, track_callbacks, 0);
566  lua_pushstring(L, Track);
567  lua_setfield(L, -2, "__metatable");
568  lua_pop(L, 1);
569 
570  // The sound source metatable
572  static luaL_Reg source_callbacks[] {
573  {"__gc", impl_source_collect},
574  { "__index", impl_source_get },
575  { "__newindex", impl_source_set },
576  { "__eq", impl_source_eq },
577  { nullptr, nullptr },
578  };
579  luaL_setfuncs(L, source_callbacks, 0);
581  lua_setfield(L, -2, "__metatable");
582 
583  return "Adding music playlist table...\n";
584  }
585 }
void empty_playlist()
Definition: sound.cpp:611
std::decay_t< T > lua_check(lua_State *L, int n)
Definition: push_check.hpp:370
#define modify_bool_attrib(name, accessor)
Definition: lua_common.hpp:386
void write(config &cfg) const
Serializes information into cfg as a new (appended) child of key "sound_source".
LUALIB_API void * luaL_checkudata(lua_State *L, int ud, const char *tname)
Definition: lauxlib.cpp:345
unsigned int get_num_tracks()
Definition: sound.cpp:220
LUA_API void lua_createtable(lua_State *L, int narray, int nrec)
Definition: lapi.cpp:728
static int impl_source_eq(lua_State *L)
Definition: lua_audio.cpp:451
static int impl_sndsrc_set(lua_State *L)
Adds or removes a sound source by its ID Key: sound source ID Value: Table containing keyword argumen...
Definition: lua_audio.cpp:357
sound::music_track & operator*()
Definition: lua_audio.cpp:44
std::string join(const T &v, const std::string &s=",")
Generates a new string joining container items in a list.
std::shared_ptr< music_track > get_current_track()
Definition: sound.cpp:207
LUA_API void lua_pushboolean(lua_State *L, int b)
Definition: lapi.cpp:581
static int impl_audio_get(lua_State *L)
Gets the current sound volume.
Definition: lua_audio.cpp:476
static int intf_music_commit(lua_State *)
Definition: lua_audio.cpp:262
bool contains(const pane::item &item, const std::string &tag, const text_box &text_box)
A filter testing whether a search string is used in a text.
Definition: filter.hpp:63
static lua_music_track * get_track(lua_State *L, int i)
Definition: lua_audio.cpp:70
#define a
static lg::log_domain log_audio("audio")
LUA_API void lua_rawseti(lua_State *L, int idx, lua_Integer n)
Definition: lapi.cpp:889
LUA_API int lua_gettop(lua_State *L)
Definition: lapi.cpp:168
child_itors child_range(config_key_type key)
Definition: config.cpp:356
static lua_sound_source & push_source(lua_State *L, const soundsource::sourcespec &spec)
Definition: lua_audio.cpp:93
void remove_track(unsigned int i)
Definition: sound.cpp:245
#define lua_remove(L, idx)
Definition: lua.h:391
std::shared_ptr< sound::music_track > track
Definition: lua_audio.cpp:37
#define return_string_attrib(name, accessor)
Definition: lua_common.hpp:238
#define lua_tointeger(L, i)
Definition: lua.h:362
static int impl_sndsrc_get(lua_State *L)
Get an existing sound source Key: The sound source ID.
Definition: lua_audio.cpp:340
static int impl_source_collect(lua_State *L)
Definition: lua_audio.cpp:377
std::shared_ptr< music_track > get_previous_music_track()
Definition: sound.cpp:211
void set_fade_range(int value)
static int impl_track_collect(lua_State *L)
Destroys a lua_music_track object before it is collected (__gc metamethod).
Definition: lua_audio.cpp:106
#define lua_tonumber(L, i)
Definition: lua.h:361
void remove(const std::string &id)
Definition: soundsource.cpp:65
Audio output for sound and music.
Definition: sound.cpp:40
void play_music_once(const std::string &file)
Definition: sound.cpp:602
#define return_vector_string_attrib(name, accessor)
Definition: lua_common.hpp:301
LUALIB_API void luaL_setmetatable(lua_State *L, const char *tname)
Definition: lauxlib.cpp:324
void lua_push(lua_State *L, const T &val)
Definition: push_check.hpp:384
void set_minimum_delay(int value)
void write_music_play_list(config &snapshot)
Definition: sound.cpp:851
map_location luaW_checklocation(lua_State *L, int index)
Converts an optional table or pair of integers to a map location object.
Definition: lua_common.cpp:725
soundsource::sourcespec * operator->()
Definition: lua_audio.cpp:85
#define modify_float_attrib_check_range(name, accessor, allowed_min, allowed_max)
Definition: lua_common.hpp:374
const std::vector< map_location > & get_locations() const
static int intf_music_play(lua_State *L)
Definition: lua_audio.cpp:196
#define lua_pop(L, n)
Definition: lua.h:364
const std::string & id() const
static int impl_music_set(lua_State *L)
Definition: lua_audio.cpp:153
#define b
bool valid() const
Definition: lua_audio.cpp:41
static int impl_music_len(lua_State *L)
Definition: lua_audio.cpp:191
static const char * Track
Definition: lua_audio.cpp:33
static int intf_music_add(lua_State *L)
Definition: lua_audio.cpp:209
static int intf_music_next(lua_State *)
Definition: lua_audio.cpp:201
LUALIB_API int luaL_argerror(lua_State *L, int arg, const char *extramsg)
Definition: lauxlib.cpp:175
#define modify_string_attrib(name, accessor)
Definition: lua_common.hpp:329
#define return_int_attrib(name, accessor)
Definition: lua_common.hpp:249
bool luaW_getglobal(lua_State *L, const std::vector< std::string > &path)
Pushes the value found by following the variadic names (char *), if the value is not nil...
Definition: lua_common.cpp:874
bool luaW_toboolean(lua_State *L, int n)
Definition: lua_common.cpp:893
static lua_music_track * push_track(lua_State *L, int i)
Definition: lua_audio.cpp:58
void set_full_range(int value)
bool check_shrouded() const
LUA_API void * lua_newuserdatauv(lua_State *L, size_t size, int nuvalue)
Definition: lapi.cpp:1311
std::shared_ptr< sound::music_track > operator->()
Definition: lua_audio.cpp:50
static int impl_track_eq(lua_State *L)
Definition: lua_audio.cpp:313
#define modify_int_attrib_check_range(name, accessor, allowed_min, allowed_max)
Definition: lua_common.hpp:351
static int impl_source_set(lua_State *L)
Definition: lua_audio.cpp:410
static int impl_audio_set(lua_State *L)
Sets the current sound volume.
Definition: lua_audio.cpp:489
LUA_API int lua_setmetatable(lua_State *L, int objindex)
Definition: lapi.cpp:901
const std::string & files() const
void set_loops(int value)
static const char * Source
Definition: lua_audio.cpp:34
int get_sound_volume()
Definition: sound.cpp:1078
void set_sound_volume(int vol)
Definition: sound.cpp:1087
LUA_API void lua_pushnil(lua_State *L)
Definition: lapi.cpp:473
LUA_API void lua_pushnumber(lua_State *L, lua_Number n)
Definition: lapi.cpp:481
void set_music_volume(int vol)
Definition: sound.cpp:1067
void set_check_shrouded(bool value)
#define lua_isboolean(L, n)
Definition: lua.h:376
bool luaW_toconfig(lua_State *L, int index, config &cfg)
Converts an optional table or vconfig to a config object.
Definition: lua_common.cpp:745
#define return_cfg_attrib(name, accessor)
Definition: lua_common.hpp:279
LUALIB_API int luaL_newmetatable(lua_State *L, const char *tname)
Definition: lauxlib.cpp:311
Sound source info class.
#define lua_isnil(L, n)
Definition: lua.h:375
std::size_t i
Definition: function.cpp:940
soundsource::manager * soundsources
Definition: resources.cpp:27
LUALIB_API lua_Integer luaL_checkinteger(lua_State *L, int arg)
Definition: lauxlib.cpp:442
LUA_API void lua_rawset(lua_State *L, int idx)
Definition: lapi.cpp:877
void add(const sourcespec &source)
Definition: soundsource.cpp:50
lua_music_track(std::shared_ptr< sound::music_track > new_track)
Definition: lua_audio.cpp:40
Internal representation of music tracks.
static int intf_music_remove(lua_State *L)
Definition: lua_audio.cpp:250
std::string register_table(lua_State *L)
Definition: lua_audio.cpp:508
static int impl_track_get(lua_State *L)
Definition: lua_audio.cpp:267
std::size_t index(const std::string &str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
Definition: unicode.cpp:71
LUA_API int lua_isinteger(lua_State *L, int idx)
Definition: lapi.cpp:279
LUA_API int lua_isnumber(lua_State *L, int idx)
Definition: lapi.cpp:285
int get_music_volume()
Definition: sound.cpp:1058
void set_files(const std::string &f)
LUALIB_API int luaL_error(lua_State *L, const char *fmt,...)
Definition: lauxlib.cpp:234
static int impl_music_get(lua_State *L)
Definition: lua_audio.cpp:113
void set_chance(int value)
const soundsource::sourcespec * operator->() const
Definition: lua_audio.cpp:88
LUA_API lua_Unsigned lua_rawlen(lua_State *L, int idx)
Definition: lapi.cpp:402
#define return_bool_attrib(name, accessor)
Definition: lua_common.hpp:269
int sound_volume()
Definition: general.cpp:574
bool luaW_getmetafield(lua_State *L, int idx, const char *key)
Like luaL_getmetafield, but returns false if key is an empty string or begins with two underscores...
Definition: lua_common.cpp:512
#define f
#define lua_istable(L, n)
Definition: lua.h:373
std::vector< std::string > split(const config_attribute_value &val)
void play_music_config(const config &music_node, bool allow_interrupt_current_track, int i)
Definition: sound.cpp:704
static int impl_source_get(lua_State *L)
Definition: lua_audio.cpp:384
std::optional< unsigned int > get_current_track_index()
Definition: sound.cpp:200
void luaW_pushlocation(lua_State *L, const map_location &ml)
Converts a map location object to a Lua table pushed at the top of the stack.
Definition: lua_common.cpp:665
#define return_float_attrib(name, accessor)
Definition: lua_common.hpp:259
const soundsource::sourcespec & operator*() const
Definition: lua_audio.cpp:82
Standard logging facilities (interface).
lua_sound_source(const soundsource::sourcespec &spec)
Definition: lua_audio.cpp:77
std::shared_ptr< const sound::music_track > operator->() const
Definition: lua_audio.cpp:53
soundsource::sourcespec spec
Definition: lua_audio.cpp:75
void commit_music_changes()
Definition: sound.cpp:822
void set_track(unsigned int i, const std::shared_ptr< music_track > &to)
Definition: sound.cpp:238
static int intf_music_clear(lua_State *)
Definition: lua_audio.cpp:245
LUALIB_API void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup)
Definition: lauxlib.cpp:904
const sound::music_track & operator*() const
Definition: lua_audio.cpp:47
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:59
void play_track(unsigned int i)
Definition: sound.cpp:628
void set_check_fogged(bool value)
static int impl_track_set(lua_State *L)
Definition: lua_audio.cpp:299
static map_location::DIRECTION n
LUA_API void lua_pushinteger(lua_State *L, lua_Integer n)
Definition: lapi.cpp:489
LUA_API const char * lua_pushstring(lua_State *L, const char *s)
Definition: lapi.cpp:514
LUA_API void lua_setfield(lua_State *L, int idx, const char *k)
Definition: lapi.cpp:837
LUA_API int lua_next(lua_State *L, int idx)
Definition: lapi.cpp:1220
soundsource::sourcespec & operator*()
Definition: lua_audio.cpp:79
lua_music_track(int i)
Definition: lua_audio.cpp:39
bool luaW_tolocation(lua_State *L, int index, map_location &loc)
Converts an optional table or pair of integers to a map location object.
Definition: lua_common.cpp:676
int music_volume()
Definition: general.cpp:559
#define modify_int_attrib(name, accessor)
Definition: lua_common.hpp:340
static lua_sound_source & get_source(lua_State *L, int i)
Definition: lua_audio.cpp:99
void set_locations(const std::vector< map_location > &locs)
#define luaL_checkstring(L, n)
Definition: lauxlib.h:138