From 3873192547f6544d9d58d143d62d7c0735401116 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barra=20=C3=93=20Cath=C3=A1in?= Date: Mon, 20 Nov 2023 21:32:53 +0000 Subject: [PATCH] Basic Scheme implementations of player structures and messaging. --- lisp/messaging.scm | 18 ++++++++++++ lisp/structures.scm | 67 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 lisp/messaging.scm create mode 100644 lisp/structures.scm diff --git a/lisp/messaging.scm b/lisp/messaging.scm new file mode 100644 index 0000000..fdf7dc4 --- /dev/null +++ b/lisp/messaging.scm @@ -0,0 +1,18 @@ +;;;; This file is part of SilverMUD. +;;;; structures.scm defines various variables and functions used for interacting with the player's +;;;; via chat output from the Scheme enviroment of SilverMUD. +(define-module (silvermud messaging)) +(use-modules (silvermud primitives)) + +(define message-everyone (lambda (name content) + (push-output-message *global-output-queue* #f *global-player-list* + 8 name content))) +(define system-message (lambda (contennt) + (push-output-message *global-output-queue* #f *global-player-list* + 0 "" content))) + +(define message-expression (lambda (expression) + (system-message (format #f "~a" expression)))) + +;; Export everything! +(export message-everyone system-message message-expression) diff --git a/lisp/structures.scm b/lisp/structures.scm new file mode 100644 index 0000000..cc45cc1 --- /dev/null +++ b/lisp/structures.scm @@ -0,0 +1,67 @@ +;;;; This file is part of SilverMUD. +;;;; structures.scm defines various variables and functions used for interacting with C structures +;;;; from the Scheme enviroment of SilverMUD. +(define-module (silvermud structures)) +(use-modules (system foreign) + (silvermud primitives)) + +;;; struct PlayerList: + +;; The layout of the struct PlayerList: +(define *player-list-structure* (list size_t '* '*)) + +;; Pretty-format the player list header: +(define (player-list-header->string player-list-pointer) + "Format a struct PlayerList pointer into a string." + (if (not (null-pointer? player-list-pointer)) + (let ((structure (parse-c-struct player-list-pointer *player-list-structure*))) + (format #f + "Players in list: ~d.\nHead: ~a. \nTail: ~a.\n" + (list-ref structure 0) (list-ref structure 1) (list-ref structure 2))))) + +;; Create a list of strings representing all players in a list: +(define (list-players player-list-pointer) + "List all players in a given C PlayerList as a list of strings." + (if (not (null-pointer? player-list-pointer)) ; Check we're not dereferencing a null pointer. + (build-list-players + (list-ref (parse-c-struct player-list-pointer *player-list-node-structure*) 2)))) + +(define (build-list-players pointer) + (if (not (null-pointer? pointer)) + (let* ((node (parse-c-struct pointer *player-list-node-structure*)) + (player (parse-c-struct (list-ref node 0) *player-structure*))) + (cons (pointer->string (list-ref player 1)) (build-list-players (list-ref node 1)))) + '())) + +;;; struct PlayerListNode: + +;; Used to interact with struct PlayerListNode: +(define *player-list-node-structure* (list '* '* '*)) + +;; Pretty-format the player list node: +(define (player-list-node->string player-list-node-pointer) + "Format a struct PlayerListNode pointer into a string." + (if (not (null-pointer? player-list-node-pointer)) + (let ((structure (parse-c-struct player-list-node-pointer *player-list-node-structure*))) + (format #f + "Player pointer: ~a.\nNext: ~a. \nPrevious: ~a.\n" + (list-ref structure 0) (list-ref structure 1) (list-ref structure 2))))) + +;;; struct Player: + +; Used to interact with struct Player: +(define *player-structure* (list '* '*)) + +(define (player->string player-info-pointer) + "Format a struct Player pointer into a string." + (if (not (null-pointer? player-info-pointer)) + (let ((structure (parse-c-struct player-info-pointer *player-structure*))) + (display (null-pointer? (list-ref structure 1))) + (format #f + "Player Name: ~a\n" (if (null-pointer? (list-ref structure 1)) + (pointer->bytevector (list-ref structure 1) 64) + #f))))) + +;; Export everything! +(export *player-list-structure* *player-list-node-structure* *player-structure* + player->string player-list-header->string player-list-node->string list-players)