| 108 | } |
| 109 | |
| 110 | void broadcast(ScriptWorld &sw |
| 111 | , const char *function_name |
| 112 | , const ArgType::Enum *arg_types |
| 113 | , const Arg *args |
| 114 | , u32 num_args |
| 115 | ) |
| 116 | { |
| 117 | if (sw._disable_callbacks) |
| 118 | return; |
| 119 | |
| 120 | LuaStack stack(sw._lua_environment->L); |
| 121 | |
| 122 | for (u32 i = 0; i < array::size(sw._script); ++i) { |
| 123 | lua_rawgeti(stack.L, LUA_REGISTRYINDEX, sw._script[i].module_ref); |
| 124 | lua_getfield(stack.L, -1, function_name); |
| 125 | |
| 126 | if (lua_isnil(stack.L, -1)) { |
| 127 | stack.pop(2); |
| 128 | continue; |
| 129 | } |
| 130 | |
| 131 | stack.push_args(arg_types, args, num_args); |
| 132 | |
| 133 | int status = sw._lua_environment->call(num_args, 0); |
| 134 | if (status != LUA_OK) { |
| 135 | report(stack.L, status); |
| 136 | device()->pause(); |
| 137 | } |
| 138 | stack.pop(1); |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | void multicast(ScriptWorld &sw |
| 143 | , const char *function_name |
no test coverage detected