MCPcopy Create free account
hub / github.com/defold/defold / Msg_Post

Function Msg_Post

engine/script/src/script_msg.cpp:486–556  ·  view source on GitHub ↗

posts a message to a receiving URL * * Post a message to a receiving URL. The most common case is to send messages * to a component. If the component part of the receiver is omitted, the message * is broadcast to all components in the game object. * * The following receiver shorthands are available: * * - `"."` the current game object * - `"#"` the curr

Source from the content-addressed store, hash-verified

484 * ```
485 */
486 int Msg_Post(lua_State* L)
487 {
488 int top = lua_gettop(L);
489 if (lua_isnil(L, 1))
490 {
491 return luaL_error(L, "The receiver shouldn't be `nil`");
492 }
493
494 dmMessage::URL receiver;
495 dmMessage::URL sender;
496 ResolveURL(L, 1, &receiver, &sender);
497
498 dmhash_t message_id;
499 if (lua_isstring(L, 2))
500 {
501 message_id = dmHashString64(lua_tostring(L, 2));
502 }
503 else
504 {
505 message_id = CheckHash(L, 2);
506 }
507
508 char DM_ALIGNED(16) data[MAX_MESSAGE_DATA_SIZE];
509 uint32_t data_size = 0;
510
511
512 const dmDDF::Descriptor* desc = dmDDF::GetDescriptorFromHash(message_id);
513 if (desc != 0)
514 {
515 if (desc->m_Size > MAX_MESSAGE_DATA_SIZE)
516 {
517 return luaL_error(L, "The message is too large to be sent (%d bytes, max is %d).", desc->m_Size, MAX_MESSAGE_DATA_SIZE);
518 }
519 if (top > 2)
520 {
521 luaL_checktype(L, 3, LUA_TTABLE);
522 lua_pushvalue(L, 3);
523 }
524 else
525 {
526 lua_newtable(L);
527 }
528 data_size = dmScript::CheckDDF(L, desc, data, MAX_MESSAGE_DATA_SIZE, -1);
529 lua_pop(L, 1);
530 }
531 else if (top > 2)
532 {
533 if (!lua_isnil(L, 3))
534 {
535 data_size = dmScript::CheckTable(L, data, MAX_MESSAGE_DATA_SIZE, 3);
536 }
537 }
538
539 assert(top == lua_gettop(L));
540
541 dmMessage::Result result = dmMessage::Post(&sender, &receiver, message_id, 0, (uintptr_t) desc, data, data_size, 0);
542 if (result == dmMessage::RESULT_SOCKET_NOT_FOUND)
543 {

Callers

nothing calls this directly

Calls 15

lua_gettopFunction · 0.85
luaL_errorFunction · 0.85
lua_isstringFunction · 0.85
CheckHashFunction · 0.85
GetDescriptorFromHashFunction · 0.85
luaL_checktypeFunction · 0.85
lua_pushvalueFunction · 0.85
CheckDDFFunction · 0.85
CheckTableFunction · 0.85
UrlToStringFunction · 0.85
dmHashReverseSafe64Function · 0.85
GetSocketNameFunction · 0.85

Tested by

no test coverage detected