Basic global messaging functions for Scheme
This commit is contained in:
parent
2acbe5e19b
commit
e11a7b3a76
|
@ -106,6 +106,11 @@ int main (int argc, char ** argv)
|
|||
// Create some structures needed to store global state:
|
||||
struct PlayerList * globalPlayerList = createPlayerList();
|
||||
struct OutputQueue * globalOutputQueue = createOutputQueue();
|
||||
|
||||
scm_c_define_gsubr("push-output-message", 6, 0, 0, &push_output_message);
|
||||
scm_c_define("*globalPlayerList*", scm_from_pointer(globalPlayerList, NULL));
|
||||
scm_c_define("*globalOutputQueue*", scm_from_pointer(globalOutputQueue, NULL));
|
||||
|
||||
// Start a REPL thread:
|
||||
//pthread_t schemeREPLThread;
|
||||
//pthread_create(&schemeREPLThread, NULL, schemeREPLHandler, NULL);
|
||||
|
@ -214,10 +219,10 @@ int main (int argc, char ** argv)
|
|||
continue;
|
||||
}
|
||||
// ONLY FOR DEMO
|
||||
]
|
||||
|
||||
pushOutputMessage(globalOutputQueue, false, globalPlayerList, LOCAL_CHAT,
|
||||
connection->player->name, message.content,
|
||||
MESSAGE_NAME_LENGTH, MESSAGE_CONTENT_LENGTH);
|
||||
MESSAGE_NAME_LENGTH, MESSAGE_CONTENT_LENGTH);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
@ -14,8 +14,8 @@ struct OutputMessage
|
|||
{
|
||||
// Allows for easy reuse of existing player lists, such as the global list
|
||||
// or an area's playerlist:
|
||||
bool deallocatePlayerList;
|
||||
|
||||
bool deallocatePlayerList;
|
||||
|
||||
struct OutputMessage * next;
|
||||
struct PlayerList * recepients;
|
||||
struct ServerToClientMessage * message;
|
||||
|
@ -37,7 +37,7 @@ size_t pushOutputMessage(struct OutputQueue * const queue,
|
|||
const char const * name, const char const * content,
|
||||
const size_t nameLength, const size_t contentLength);
|
||||
|
||||
struct OutputMessage * popOutputMessage();
|
||||
struct OutputMessage * popOutputMessage(struct OutputQueue * queue);
|
||||
|
||||
void deallocateOutputMessage(struct OutputMessage ** message);
|
||||
|
||||
|
|
|
@ -3,9 +3,37 @@
|
|||
// | Copyright (C) 2023, Barra Ó Catháin |
|
||||
// | See end of file for copyright notice. |
|
||||
// ===========================================
|
||||
#include <stdbool.h>
|
||||
#include <libguile.h>
|
||||
|
||||
SCM scheme_get_player_by_name(SCM name);
|
||||
#include "../messages.h"
|
||||
#include "output-queue.h"
|
||||
|
||||
SCM scheme_get_player_by_name(SCM name, SCM queue);
|
||||
|
||||
SCM push_output_message(SCM queue, SCM deallocate_list, SCM recepients, SCM type, SCM name, SCM content)
|
||||
{
|
||||
// Convert our scheme values into appropriate data types:
|
||||
struct OutputQueue * queue_c = scm_to_pointer(queue);
|
||||
bool deallocate_list_c = scm_to_bool(deallocate_list);
|
||||
struct PlayerList * recepients_c = scm_to_pointer(recepients);
|
||||
enum MessageTypes type_c = scm_to_int(type);
|
||||
|
||||
// Turn the Scheme strings into C strings:
|
||||
size_t nameLength, contentLength;
|
||||
char * name_c = scm_to_locale_stringn(name, &nameLength);
|
||||
char * content_c = scm_to_locale_stringn(content, &contentLength);
|
||||
|
||||
// Call the C function:
|
||||
pushOutputMessage(queue_c, deallocate_list_c, recepients_c, type_c, name_c, content_c,
|
||||
nameLength, contentLength);
|
||||
|
||||
// Free the created C strings:
|
||||
free(name_c);
|
||||
free(content_c);
|
||||
|
||||
return SCM_BOOL_T;
|
||||
}
|
||||
|
||||
// ==========================================================
|
||||
// | End of scheme-integration.c, copyright notice follows. |
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
|
||||
SCM scheme_get_player_by_name(SCM name);
|
||||
|
||||
SCM push_output_message(SCM queue, SCM deallocate_list, SCM recepients, SCM type, SCM name, SCM content);
|
||||
|
||||
#endif
|
||||
// ==========================================================
|
||||
// | End of scheme-integration.h, copyright notice follows. |
|
||||
|
|
Loading…
Reference in New Issue