summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-03-11 03:15:40 -0500
committerJesse Luehrs <doy@tozt.net>2013-03-11 03:15:40 -0500
commitd62ab0a4be7438efc1a30241fe9ef85e7e8c4972 (patch)
tree95f58e7bf5945e88f3f27e7746544c17441e75bd
parentbd93ba9d4419899694f16317d288125762dcaa33 (diff)
downloadrust-lua-d62ab0a4be7438efc1a30241fe9ef85e7e8c4972.tar.gz
rust-lua-d62ab0a4be7438efc1a30241fe9ef85e7e8c4972.zip
provide a method interface
-rw-r--r--lua.rs46
-rw-r--r--main.rs8
2 files changed, 38 insertions, 16 deletions
diff --git a/lua.rs b/lua.rs
index 7a1fc37..bff1a2b 100644
--- a/lua.rs
+++ b/lua.rs
@@ -2,8 +2,27 @@
#[crate_type = "lib"];
-pub enum lua_State {}
-enum lua_CFunction {}
+pub struct State {
+ priv state: *lua_State,
+}
+
+impl State {
+ fn close(self) {
+ close(self)
+ }
+
+ fn openlibs(self) {
+ openlibs(self)
+ }
+
+ fn loadstring(self, string: &str) -> Status {
+ loadstring(self, string)
+ }
+
+ fn call(self, nargs: int, nresults: int) {
+ call(self, nargs, nresults)
+ }
+}
pub enum Status {
OK = 0,
@@ -15,21 +34,21 @@ pub enum Status {
ERRERR = 6,
}
-pub fn newstate() -> *lua_State {
- lua::luaL_newstate()
+pub fn newstate() -> State {
+ State { state: lua::luaL_newstate() }
}
-pub fn close(state: *lua_State) {
- lua::lua_close(state)
+pub fn close(state: State) {
+ lua::lua_close(state.state)
}
-pub fn openlibs(state: *lua_State) {
- lua::luaL_openlibs(state)
+pub fn openlibs(state: State) {
+ lua::luaL_openlibs(state.state)
}
-pub fn loadstring(state: *lua_State, string: &str) -> Status {
+pub fn loadstring(state: State, string: &str) -> Status {
let status = do str::as_c_str(string) |c_string| {
- lua::luaL_loadstring(state, c_string)
+ lua::luaL_loadstring(state.state, c_string)
};
match status {
0 => OK,
@@ -40,9 +59,9 @@ pub fn loadstring(state: *lua_State, string: &str) -> Status {
}
}
-pub fn call(state: *lua_State, nargs: int, nresults: int) {
+pub fn call(state: State, nargs: int, nresults: int) {
lua::lua_callk(
- state,
+ state.state,
nargs as libc::c_int,
nresults as libc::c_int,
0 as libc::c_int,
@@ -50,6 +69,9 @@ pub fn call(state: *lua_State, nargs: int, nresults: int) {
)
}
+enum lua_State {}
+enum lua_CFunction {}
+
extern mod lua {
fn luaL_newstate() -> *lua_State;
fn lua_close(state: *lua_State);
diff --git a/main.rs b/main.rs
index 1e50e6f..b96119c 100644
--- a/main.rs
+++ b/main.rs
@@ -2,8 +2,8 @@ extern mod lua;
fn main() {
let state = lua::newstate();
- lua::openlibs(state);
- lua::loadstring(state, os::args()[1]);
- lua::call(state, 0, 0);
- lua::close(state);
+ state.openlibs();
+ state.loadstring(os::args()[1]);
+ state.call(0, 0);
+ state.close();
}