-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Full changelist will be in 2.0.0. Essentially a lot of breaking changes, added Userdata support for Vector and Angle, some missing lua c api functions, and a lot of documentation.
- Loading branch information
Showing
23 changed files
with
1,066 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
[package] | ||
name = "gmod_is_even" | ||
description = "Binary module that exposes a function called 'is_even' that does what it says." | ||
version = "0.2.0" | ||
version = "0.3.0" | ||
edition = "2021" | ||
publish = false | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
rglua = { path = "../.." } | ||
rglua = { path = "../../rglua" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "vector" | ||
description = "Binary module that adds some extra functions to the gmod Vector type" | ||
version = "0.1.0" | ||
edition = "2021" | ||
publish = false | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
rglua = { path = "../../rglua" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# 🔢 ``vector`` | ||
Binary module that adds some extra functions to the ``Vector`` type. | ||
|
||
## Vector:IsPositive() | ||
Returns if the vector consists of positive numbers | ||
|
||
## Vector:GetPow(n: number) | ||
Returns the vector multiplied by itself n times (exp ^) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use rglua::prelude::*; | ||
|
||
#[lua_function] | ||
fn is_positive(l: LuaState) -> i32 { | ||
let vec = luaL_checkvector(l, 1); | ||
lua_pushboolean(l, (vec.x > 0.0 && vec.y > 0.0 && vec.z > 0.0) as i32); | ||
1 | ||
} | ||
|
||
#[lua_function] | ||
fn get_pow(l: LuaState) -> i32 { | ||
let vec = luaL_checkvector(l, 1); | ||
let by = luaL_checknumber(l, 2) as f32; | ||
|
||
lua_pushvector(l, Vector::new(vec.x.powf(by), vec.y.powf(by), vec.z.powf(by))); | ||
1 | ||
} | ||
|
||
// Note that since this is #[gmod_open] the name of the function does not matter | ||
// This is the same for #[gmod_close] | ||
#[gmod_open] | ||
fn open(l: LuaState) -> i32 { | ||
// Create a library consisting of functions to export to gmod. | ||
let lib = reg! [ | ||
"IsPositive" => is_positive, | ||
"GetPow" => get_pow | ||
]; | ||
|
||
// Get the ``Vector`` metatable from the lua registry and put it onto the stack. | ||
luaL_getmetatable(l, cstr!("Vector")); | ||
|
||
// Give a null pointer as the libname so that luaL_register knows we are trying to instead add these functions to the value on top of the stack; | ||
// This being the Vector metatable at (-1). | ||
luaL_register(l, std::ptr::null(), lib.as_ptr()); | ||
|
||
// Return nothing (0 objects) | ||
0 | ||
} | ||
|
||
#[gmod_close] | ||
fn close(l: LuaState) -> i32 { | ||
printgm!(l, "Goodbye garrysmod!"); | ||
0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
use super::common::StudioHdr; | ||
use super::prelude::*; | ||
|
||
iface! { | ||
#[version("MDLCache004")] | ||
#[file("datacache.dll")] | ||
pub abstract struct IMdlCache {}; | ||
|
||
#[version("")] | ||
#[file("")] | ||
pub abstract struct IMdlCacheNotify {}; | ||
} | ||
|
||
#[repr(C)] | ||
pub enum MDLCacheDataType { | ||
// Callbacks to get called when data is loaded or unloaded for these: | ||
StudioHDR = 0, | ||
StudioHWData, | ||
VCollide, | ||
|
||
// Callbacks NOT called when data is loaded or unloaded for these: | ||
AnimBlock, | ||
VirtualModel, | ||
Vertexes, | ||
DecodedAnimBlock, | ||
} | ||
|
||
impl IMdlCacheNotify { | ||
#[virtual_index(0)] | ||
/// Called right after data is loaded | ||
pub fn OnDataLoaded(&self, ty: MDLCacheDataType, handle: MDLHandle) -> () {} | ||
|
||
#[virtual_index(1)] | ||
/// Called right before data is unloaded | ||
pub fn OnDataUnloaded(&self, ty: MDLCacheDataType, handle: MDLHandle) -> () {} | ||
} | ||
|
||
pub type MDLHandle = c_ushort; | ||
pub type VirtualModel = c_void; // Todo? | ||
|
||
const MAX_NUM_LODS: usize = 8; | ||
|
||
#[repr(C)] | ||
pub struct VertexFileHeader { | ||
id: c_int, | ||
version: c_int, | ||
checksum: c_int, | ||
numLODs: c_int, | ||
numLODVertexes: [c_int; MAX_NUM_LODS], | ||
numFixups: c_int, | ||
fixupTableStart: c_int, | ||
vertexDataStart: c_int, | ||
tangentDataStart: c_int, | ||
} | ||
|
||
impl IMdlCache { | ||
#[virtual_index(0)] | ||
pub fn SetCacheNotify(&self, pNotify: *mut IMdlCacheNotify) -> () {} | ||
|
||
#[virtual_index(1)] | ||
pub fn FindMDL(&self, pMDLRelativePath: *const c_char) -> MDLHandle {} | ||
|
||
#[virtual_index(2)] | ||
pub fn AddRef(&self, handle: MDLHandle) -> c_int {} | ||
|
||
#[virtual_index(3)] | ||
pub fn Release(&self, handle: MDLHandle) -> c_int {} | ||
|
||
#[virtual_index(4)] | ||
pub fn GetRef(&self, handle: MDLHandle) -> c_int {} | ||
|
||
#[virtual_index(5)] | ||
pub fn GetStudioHdr(&self, handle: MDLHandle) -> *mut StudioHdr {} | ||
|
||
#[virtual_index(9)] | ||
pub fn GetVirtualModel(&self, handle: MDLHandle) -> *mut VirtualModel {} | ||
|
||
#[virtual_index(11)] | ||
pub fn GetVertexData(&self, handle: MDLHandle) -> *mut VertexFileHeader {} | ||
|
||
#[virtual_index(12)] | ||
pub fn TouchAllData(&self, handle: MDLHandle) -> () {} | ||
|
||
#[virtual_index(13)] | ||
pub fn SetUserData(&self, handle: MDLHandle, pData: *mut c_void) -> () {} | ||
|
||
#[virtual_index(14)] | ||
pub fn GetUserData(&self, handle: MDLHandle) -> *mut c_void {} | ||
|
||
#[virtual_index(15)] | ||
pub fn IsErrorModel(&self, handle: MDLHandle) -> bool {} | ||
|
||
#[virtual_index(18)] | ||
pub fn GetModelName(&self, handle: MDLHandle) -> *const c_char {} | ||
|
||
#[virtual_index(19)] | ||
pub fn GetVirtualModelFast( | ||
&self, | ||
pStudioHdr: *const StudioHdr, | ||
handle: MDLHandle, | ||
) -> *mut VirtualModel { | ||
} | ||
|
||
#[virtual_index(20)] | ||
pub fn BeginLock(&self) -> () {} | ||
|
||
#[virtual_index(21)] | ||
pub fn EndLock(&self) -> () {} | ||
} |
Oops, something went wrong.