Update C Codebase to use modules for Scheme primitives

This commit is contained in:
Barra Ó Catháin 2023-11-20 21:30:30 +00:00 committed by Barry Kane
parent 4d13547ae6
commit fa3df0cc69
3 changed files with 31 additions and 9 deletions

View File

@ -130,11 +130,6 @@ int main (int argc, char ** argv)
// Initialize Scheme:
scm_init_guile();
// Start the REPL server on a UNIX socket:
scm_c_eval_string("(begin (use-modules (system repl server))"
"(if (file-exists? \"silvermud-repl\") (delete-file \"silvermud-repl\"))"
"(spawn-server (make-unix-domain-server-socket #:path \"silvermud-repl\")))");
// Create a socket to listen for connections on:
int masterSocket = socket(AF_INET, SOCK_STREAM, 0);
if (masterSocket < 0)
@ -202,10 +197,19 @@ int main (int argc, char ** argv)
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));
// Define a module for use in the REPL containing our needed primitives:
SchemeModulePointers schemePointers;
schemePointers.globalPlayerList = globalPlayerList;
schemePointers.globalOutputQueue = globalOutputQueue;
scm_c_define_module("silvermud primitives", initialize_silvermud_primitives, &schemePointers);
scm_c_use_module("silvermud primitives");
// Start the REPL server on a UNIX socket:
scm_c_eval_string("(begin (use-modules (system repl server))"
"(if (file-exists? \"silvermud-repl\") (delete-file \"silvermud-repl\"))"
"(spawn-server (make-unix-domain-server-socket #:path \"silvermud-repl\")))");
// Start an output thread:
pthread_t outputThread;
pthread_create(&outputThread, NULL, outputThreadHandler, (void *)globalOutputQueue);

View File

@ -8,8 +8,18 @@
#include "../messages.h"
#include "output-queue.h"
#include "scheme-integration.h"
SCM scheme_get_player_by_name(SCM name, SCM queue);
void initialize_silvermud_primitives (void * gameState)
{
SchemeModulePointers * pointers = (SchemeModulePointers *)gameState;
scm_c_define_gsubr("push-output-message", 6, 0, 0, &push_output_message);
scm_c_define("*global-player-list*", scm_from_pointer(pointers->globalPlayerList, NULL));
scm_c_define("*global-output-queue*", scm_from_pointer(pointers->globalOutputQueue, NULL));
scm_c_export("push-output-message", "*global-player-list*", "*global-output-queue*", NULL);
}
//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)
{

View File

@ -6,6 +6,14 @@
#ifndef SCHEME_INTEGRATION_H
#define SCHEME_INTEGRATION_H
typedef struct SchemeModulePointers
{
struct PlayerList * globalPlayerList;
struct OutputQueue * globalOutputQueue;
} SchemeModulePointers;
void initialize_silvermud_primitives (void * gameState);
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);