Skip to content
This repository was archived by the owner on Nov 12, 2025. It is now read-only.

Commit a01f71c

Browse files
Vurv78Vurv78
authored andcommitted
Add arg_error, push_nil, push_bool
1 parent 31b1a29 commit a01f71c

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

glua-headers/init.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ extern "C" {
3232
void glua_push_number(lua_State* state, double number) {
3333
LUA->PushNumber(number);
3434
}
35+
void glua_push_bool(lua_State* state, bool val) {
36+
LUA->PushBool(val);
37+
}
38+
void glua_push_nil(lua_State* state) {
39+
LUA->PushNil();
40+
}
3541

3642
void glua_push_global(lua_State* state) {
3743
LUA->PushSpecial(GarrysMod::Lua::SPECIAL_GLOB);
@@ -45,8 +51,11 @@ extern "C" {
4551
LUA->SetTable(stackPos);
4652
}
4753

48-
// Call
54+
// Misc
4955
void glua_call(lua_State* state, int nargs, int nresults) {
5056
LUA->Call(nargs,nresults);
5157
}
58+
void glua_arg_error(lua_State* state, int argnum, const char* errmsg) {
59+
LUA->ArgError(argnum,errmsg);
60+
}
5261
}

src/lib.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ extern {
2424
// Push
2525
fn glua_push_string(state: LuaState, string: *const CChar);
2626
fn glua_push_number(state: LuaState, n: CDouble);
27+
fn glua_push_bool(state: LuaState, val: bool);
28+
fn glua_push_nil(state: LuaState);
29+
2730

2831
// Push (Special)
2932
fn glua_push_global(state: LuaState);
@@ -33,6 +36,7 @@ extern {
3336
fn glua_set_table(state: LuaState, stack_pos: i32);
3437

3538
fn glua_call(state: LuaState, nargs: i32, nresults: i32);
39+
fn glua_arg_error(state: LuaState, argnum: i32, errmsg: *const CChar );
3640
}
3741

3842
pub struct RLuaState {
@@ -139,14 +143,20 @@ impl RLuaState {
139143
glua_push_number(self.raw_state,num as CDouble)
140144
}
141145
pub unsafe fn push_string(&mut self, string: &str) {
142-
glua_push_string(self.raw_state,CString::new(string).unwrap().as_ptr());
146+
glua_push_string(self.raw_state,CString::new(string).unwrap().as_ptr())
143147
}
144148
pub unsafe fn push_cfunc(&mut self, func: extern fn(LuaState) -> i32) {
145149
glua_push_cfunc(self.raw_state,func)
146150
}
147151
pub unsafe fn push_global(&mut self) {
148152
glua_push_global(self.raw_state)
149153
}
154+
pub unsafe fn push_bool(&mut self, val: bool) {
155+
glua_push_bool(self.raw_state,val)
156+
}
157+
pub unsafe fn push_nil(&mut self) {
158+
glua_push_nil(self.raw_state)
159+
}
150160
}
151161

152162
/// Lua Set Functions
@@ -167,6 +177,10 @@ impl RLuaState {
167177
pub unsafe fn call(&mut self, nargs: i32, nresults: i32) {
168178
glua_call(self.raw_state,nargs,nresults)
169179
}
180+
/// Throws an error at argument <argnum> with the error message of <errmsg>
181+
pub unsafe fn arg_error(&mut self, argnum: i32, errmsg: &str) {
182+
glua_arg_error(self.raw_state,argnum, CString::new(errmsg).unwrap().as_ptr() )
183+
}
170184
}
171185

172186

0 commit comments

Comments
 (0)