Skip to content

Commit

Permalink
1.0.0
Browse files Browse the repository at this point in the history
* Use $crate instead of rglua in macros
* Add variadic support to dyn_symbols (In turn re-adds luaL_error and pushfstring
* Add lua_getinfo
* Add lua_next
* Add lua_replace
* Add lua_lessthan
* Add lua_gc
* Add rest of the functions we were missing
* Add lua_objlen
Types are now T* instead of Type::*. Same with prior enums. Deprecated old ones

* Added LuaDebug
* Added LuaAlloc
* Added LuaHook
* Added LuaReader
* Removed redundant Interface trait, vtables already adds a function to get a ptr.

I'm not gonna work on this for a while this is getting tiring. Near the completion of the library (in terms of the lua part.)
  • Loading branch information
Vurv78 committed Dec 21, 2021
1 parent 1300660 commit 8fae2a0
Show file tree
Hide file tree
Showing 7 changed files with 363 additions and 58 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ Here's a comparison and why you could use this one.
[gmod-rs]: https://crates.io/crates/gmod
[gmrs]: https://github.com/diogo464/gmrs

| Library | [rglua] | [rust-glua-sys] | [gmod-rs] | [gmrs] |
|-----------------------------------|---------|-----------------|------------|--------|
| Lua C Api Bindings | ✔️ | ✔️ | ✔️ ||
| Crates.io | ✔️ || ✔️ ||
| Library | [rglua] | [rust-glua-sys] | [gmod-rs] | [gmrs] |
|-----------------------------------|---------|-----------------|-------------|--------|
| *Full* Lua C Api Bindings | ✔️ | * | ||
| On Crates.io | ✔️ || ✔️ ||
| Proc Macros | ✔️ || ✔️ | ✔️ |
| Interfacing w/ Source SDK | ✔️ ||||
| Returning Result<> from functions | ✔️ ||| ✔️ |
| Can be used on stable | ✔️ | ✔️ || ✔️ |
| Real world examples | ✔️ || ✔️ ||
| Github Stars | 😢 | 👍 | 👑 | 🤷‍♂️ |

\* They technically do, but they depend on autogenerated bindings which is inaccurate for gmod, leading to missing functions. (See lua_resume_real)

__*You can help with that last one 😉*__
2 changes: 1 addition & 1 deletion rglua/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "rglua"
description = "Toolkit for garrysmod development with the source sdk and luajit api"
version = "0.9.0"
version = "1.0.0"
authors = ["Vurv <vurvdevelops@gmail.com>"]
keywords = ["glua", "garrysmod", "lua", "gmod"]
categories = ["api-bindings", "external-ffi-bindings", "development-tools::ffi", "game-development", "accessibility"]
Expand Down
16 changes: 0 additions & 16 deletions rglua/src/interface/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ pub(crate) mod prelude {
$vis struct $iface {
pub vtable: usize
}
impl crate::interface::Interface for $iface {
unsafe fn get_raw(&self, offset: isize) -> *mut std::ffi::c_void {
(self.vtable as *mut *mut std::ffi::c_void).offset(offset).read()
}
}
iface!( $($rest)* );
};
() => ();
Expand Down Expand Up @@ -134,14 +129,3 @@ pub fn get_from_interface(
Err(InterfaceError::FactoryNotFound)
}
}

pub trait Interface {
/// Retrieves a pointer to a function in the interface from the given offset.
/// # Arguments
/// * `offset` - offset of the function in the interface. E.g. `41` for PaintTraverse
/// # Examples
/// Todo!
/// # Safety
/// This is unsafe as it reads raw memory from the vtable. Might want to make sure it's valid
unsafe fn get_raw(&self, offset: isize) -> *mut c_void;
}
86 changes: 82 additions & 4 deletions rglua/src/lua/globals.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![allow(non_snake_case)]

use crate::types::*;

/// Index of the lua registry. What you'd get from debug.getregistry()
Expand All @@ -16,6 +14,55 @@ pub const MULTRET: c_int = -1;
pub const NUMTYPES: c_int = 9;
pub const NUMTAGS: c_int = NUMTYPES;

pub const TNONE: c_int = -1;
pub const TNIL: c_int = 0;
pub const TBOOLEAN: c_int = 1;
pub const TLIGHTUSERDATA: c_int = 2;
pub const TNUMBER: c_int = 3;
pub const TSTRING: c_int = 4;
pub const TTABLE: c_int = 5;
pub const TFUNCTION: c_int = 6;
pub const TUSERDATA: c_int = 7;
pub const TTHREAD: c_int = 8;

pub const MINSTACK: c_int = 20;

pub const OK: c_int = 0;
pub const YIELD: c_int = 1;
pub const ERRRUN: c_int = 2;
pub const ERRSYNTAX: c_int = 3;
pub const ERRMEM: c_int = 4;
pub const ERRERR: c_int = 5;

pub const GCSTOP: c_int = 0;
pub const GCRESTART: c_int = 1;
pub const GCCOLLECT: c_int = 2;
pub const GCCOUNT: c_int = 3;
pub const GCCOUNTB: c_int = 4;
pub const GCSTEP: c_int = 5;
pub const GCSETPAUSE: c_int = 6;
pub const GCSETSTEPMUL: c_int = 7;

pub const HOOKCALL: c_int = 0;
pub const HOOKRET: c_int = 1;
pub const HOOKLINE: c_int = 2;
pub const HOOKCOUNT: c_int = 3;
pub const HOOKTAILRET: c_int = 4;

pub const MASKCALL: c_int = 1 << HOOKCALL;
pub const MASKRET: c_int = 1 << HOOKRET;
pub const MASKLINE: c_int = 1 << HOOKLINE;
pub const MASKCOUNT: c_int = 1 << HOOKCOUNT;

/// Size of LuaDebug.short_src
pub const IDSIZE: usize = 128;

// This is libc's default so we'll roll with it
pub const BUFFERSIZE: usize = 8192;

// Rust doesn't work well with C Enums. So I'm just going to ditch the idea.
#[deprecated(since = "0.9.1", note = "Use rglua::lua::T* instead")]
#[allow(non_snake_case)]
pub mod Type {
#![allow(non_upper_case_globals)]

Expand All @@ -32,6 +79,7 @@ pub mod Type {
}

#[repr(i32)]
#[deprecated(since = "0.9.1", note = "Use rglua::lua::T* instead")]
pub enum Status {
Ok = 0,
Yield,
Expand All @@ -42,6 +90,8 @@ pub enum Status {
}

// Garbage collection
#[repr(i32)]
#[deprecated(since = "0.9.1", note = "Use rglua::lua::T* instead")]
pub enum Gc {
Stop = 0,
Restart,
Expand All @@ -57,6 +107,7 @@ pub enum Gc {
}

// To be used with debug.sethook
#[deprecated(since = "0.9.1", note = "Use rglua::lua::T* instead")]
pub enum Hook {
Call = 0,
Ret,
Expand All @@ -65,15 +116,41 @@ pub enum Hook {
TailCall,
}

#[deprecated(since = "0.9.1", note = "Use rglua::lua::T* instead")]
pub enum Mask {
#[allow(deprecated)]
Call = (1 << Hook::Call as i32),
#[allow(deprecated)]
Ret = (1 << Hook::Ret as i32),
#[allow(deprecated)]
Line = (1 << Hook::Line as i32),
#[allow(deprecated)]
Count = (1 << Hook::Count as i32),
}

pub mod Jit {
pub mod jit {
use super::c_int;

pub const VERSION: &str = "LuaJIT 2.0.4";
pub const VERSION_NUM: c_int = 20004; /* Version 2.0.4 = 02.00.04. */

pub const MODE_MASK: c_int = 0x00ff;

pub const MODE_ENGINE: c_int = 1; /* Set mode for whole JIT engine. */
pub const MODE_DEBUG: c_int = 2; /* Set debug mode (idx = level). */
pub const MODE_FUNC: c_int = 3; /* Change mode for a function. */
pub const MODE_ALLFUNC: c_int = 4; /* Recurse into subroutine protos. */
pub const MODE_ALLSUBFUNC: c_int = 5; /* Change only the subroutines. */
pub const MODE_TRACE: c_int = 6; /* Flush a compiled trace. */
pub const MODE_WRAPCFUNC: c_int = 0x10; /* Set wrapper mode for C function calls. */
pub const MODE_MAX: c_int = MODE_WRAPCFUNC + 1;

pub const MODE_OFF: c_int = 0x0000; /* Turn feature off. */
pub const MODE_ON: c_int = 0x0100; /* Turn feature on. */
pub const MODE_FLUSH: c_int = 0x0200; /* Flush JIT-compiled code. */

#[repr(i32)]
#[deprecated(since = "0.9.1", note = "Use rglua::lua::T* instead")]
pub enum Mode {
ENGINE,
DEBUG,
Expand All @@ -86,7 +163,8 @@ pub mod Jit {
MASK = 0x0ff, // LUAJIT_MODE_MASK
}

use super::c_int;
#[deprecated(since = "0.9.1", note = "Use rglua::lua::T* instead")]
#[allow(deprecated)]
// Associated Constants, woah
impl Mode {
pub const OFF: c_int = 0x0000;
Expand Down
Loading

0 comments on commit 8fae2a0

Please sign in to comment.