Update C Codebase to use modules for Scheme primitives
This commit is contained in:
parent
3309c034c4
commit
4fa677c09a
|
@ -37,11 +37,6 @@ int main (int argc, char ** argv)
|
||||||
// Initialize Scheme:
|
// Initialize Scheme:
|
||||||
scm_init_guile();
|
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:
|
// Create a socket to listen for connections on:
|
||||||
int masterSocket = socket(AF_INET, SOCK_STREAM, 0);
|
int masterSocket = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
if (masterSocket < 0)
|
if (masterSocket < 0)
|
||||||
|
@ -107,9 +102,18 @@ int main (int argc, char ** argv)
|
||||||
struct PlayerList * globalPlayerList = createPlayerList();
|
struct PlayerList * globalPlayerList = createPlayerList();
|
||||||
struct OutputQueue * globalOutputQueue = createOutputQueue();
|
struct OutputQueue * globalOutputQueue = createOutputQueue();
|
||||||
|
|
||||||
scm_c_define_gsubr("push-output-message", 6, 0, 0, &push_output_message);
|
// Define a module for use in the REPL containing our needed primitives:
|
||||||
scm_c_define("*globalPlayerList*", scm_from_pointer(globalPlayerList, NULL));
|
SchemeModulePointers schemePointers;
|
||||||
scm_c_define("*globalOutputQueue*", scm_from_pointer(globalOutputQueue, NULL));
|
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:
|
// Start an output thread:
|
||||||
pthread_t outputThread;
|
pthread_t outputThread;
|
||||||
|
|
|
@ -8,8 +8,18 @@
|
||||||
|
|
||||||
#include "../messages.h"
|
#include "../messages.h"
|
||||||
#include "output-queue.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)
|
SCM push_output_message(SCM queue, SCM deallocate_list, SCM recepients, SCM type, SCM name, SCM content)
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,6 +6,14 @@
|
||||||
#ifndef SCHEME_INTEGRATION_H
|
#ifndef SCHEME_INTEGRATION_H
|
||||||
#define 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 scheme_get_player_by_name(SCM name);
|
||||||
|
|
||||||
SCM push_output_message(SCM queue, SCM deallocate_list, SCM recepients, SCM type, SCM name, SCM content);
|
SCM push_output_message(SCM queue, SCM deallocate_list, SCM recepients, SCM type, SCM name, SCM content);
|
||||||
|
|
Loading…
Reference in New Issue