Function libdonet::read_dc_files
source · pub fn read_dc_files(file_paths: Vec<String>) -> DCReadResult
Expand description
Easy to use interface for the DC file parser. Handles reading +data-use_system_theme="false">
Function libdonet::read_dc_files
source · pub fn read_dc_files(file_paths: Vec<String>) -> DCReadResult
Expand description
Easy to use interface for the DC file parser. Handles reading the DC files, instantiating the lexer and parser, and either returns the DCFile object or a Parse/File error.
+Example Usage
+The following is an example of parsing a simple DC file string, +printing its DC hash in hexadecimal notation, and accessing +the elements of a defined Distributed Class:
+ +use libdonet::dcfile::DCFileInterface;
+use libdonet::dclass::{DClass, DClassInterface};
+use libdonet::globals::DCReadResult;
+use libdonet::read_dc_files;
+
+// All elements in a DC File object are thread-safe!
+use std::sync::{Arc, Mutex, MutexGuard};
+
+let dc_file: &str = "from game.ai import AnonymousContact/UD
+ from game.ai import LoginManager/AI
+ from game.world import DistributedWorld/AI
+ from game.avatar import DistributedAvatar/AI/OV
+
+ dclass AnonymousContact {
+ login(string username, string password) clsend airecv;
+ };
+
+ dclass LoginManager {
+ login(channel client, string username, string password) airecv;
+ };
+
+ dclass DistributedWorld {
+ create_avatar(channel client) airecv;
+ };
+
+ dclass DistributedAvatar {
+ set_xyzh(int16 x, int16 y, int16 z, int16 h) broadcast required;
+ indicate_intent(int16 / 10, int16 / 10) ownsend airecv;
+ };";
+
+let dc_read: DCReadResult = read_dc_files(vec![dc_file.into()]);
+
+if let Ok(mut dc_file) = dc_read {
+ println!("{}", dc_file.get_pretty_hash()); // Print the DC File Hash
+
+ let avatar_class: Arc<Mutex<DClass>> = dc_file.get_dclass_by_id(3);
+ let mut locked_class: MutexGuard<'_, DClass> = avatar_class.lock().unwrap();
+
+ println!("{}", locked_class.get_name());
+}
The output of the program would be the following:
+0x01a5Fb0c
+DistributedAvatar
+
Expand description
Expand description
DONET SOFTWARE
Copyright (c) 2024, Donet Authors.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Affero General Public License version 3. diff --git a/docs/src/libdonet/lib.rs.html b/docs/src/libdonet/lib.rs.html index e074a75..f6ce235 100644 --- a/docs/src/libdonet/lib.rs.html +++ b/docs/src/libdonet/lib.rs.html @@ -113,6 +113,61 @@ 111 112 113 +114 +115 +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 +126 +127 +128 +129 +130 +131 +132 +133 +134 +135 +136 +137 +138 +139 +140 +141 +142 +143 +144 +145 +146 +147 +148 +149 +150 +151 +152 +153 +154 +155 +156 +157 +158 +159 +160 +161 +162 +163 +164 +165 +166 +167 +168
//! DONET SOFTWARE
//!
//! Copyright (c) 2024, Donet Authors.
@@ -190,6 +245,61 @@
/// Easy to use interface for the DC file parser. Handles reading
/// the DC files, instantiating the lexer and parser, and either
/// returns the DCFile object or a Parse/File error.
+///
+/// ## Example Usage
+/// The following is an example of parsing a simple DC file string,
+/// printing its DC hash in hexadecimal notation, and accessing
+/// the elements of a defined Distributed Class:
+/// ```rust
+/// use libdonet::dcfile::DCFileInterface;
+/// use libdonet::dclass::{DClass, DClassInterface};
+/// use libdonet::globals::DCReadResult;
+/// use libdonet::read_dc_files;
+///
+/// // All elements in a DC File object are thread-safe!
+/// use std::sync::{Arc, Mutex, MutexGuard};
+///
+/// let dc_file: &str = "from game.ai import AnonymousContact/UD
+/// from game.ai import LoginManager/AI
+/// from game.world import DistributedWorld/AI
+/// from game.avatar import DistributedAvatar/AI/OV
+///
+/// dclass AnonymousContact {
+/// login(string username, string password) clsend airecv;
+/// };
+///
+/// dclass LoginManager {
+/// login(channel client, string username, string password) airecv;
+/// };
+///
+/// dclass DistributedWorld {
+/// create_avatar(channel client) airecv;
+/// };
+///
+/// dclass DistributedAvatar {
+/// set_xyzh(int16 x, int16 y, int16 z, int16 h) broadcast required;
+/// indicate_intent(int16 / 10, int16 / 10) ownsend airecv;
+/// };";
+///
+/// let dc_read: DCReadResult = read_dc_files(vec![dc_file.into()]);
+///
+/// if let Ok(mut dc_file) = dc_read {
+/// println!("{}", dc_file.get_pretty_hash()); // Print the DC File Hash
+///
+/// let avatar_class: Arc<Mutex<DClass>> = dc_file.get_dclass_by_id(3);
+/// let mut locked_class: MutexGuard<'_, DClass> = avatar_class.lock().unwrap();
+///
+/// println!("{}", locked_class.get_name());
+/// }
+/// ```
+///
+/// The output of the program would be the following:
+/// ```txt
+/// 0x01a5Fb0c
+/// DistributedAvatar
+/// ```
+/// <br><img src="https://c.tenor.com/myQHgyWQQ9sAAAAd/tenor.gif">
+///
#[cfg(feature = "dcfile")]
pub fn read_dc_files(file_paths: Vec<String>) -> globals::DCReadResult {
use crate::dclexer::Lexer;