summaryrefslogtreecommitdiffstats
path: root/lua.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-03-11 02:34:38 -0500
committerJesse Luehrs <doy@tozt.net>2013-03-11 02:34:38 -0500
commitbd93ba9d4419899694f16317d288125762dcaa33 (patch)
tree263578223520536a53fadcc23d1fe2e21d555d66 /lua.rs
downloadrust-lua-bd93ba9d4419899694f16317d288125762dcaa33.tar.gz
rust-lua-bd93ba9d4419899694f16317d288125762dcaa33.zip
initial commit
Diffstat (limited to 'lua.rs')
-rw-r--r--lua.rs69
1 files changed, 69 insertions, 0 deletions
diff --git a/lua.rs b/lua.rs
new file mode 100644
index 0000000..7a1fc37
--- /dev/null
+++ b/lua.rs
@@ -0,0 +1,69 @@
+#[link(name = "lua", vers = "0.0.1", author = "doy")];
+
+#[crate_type = "lib"];
+
+pub enum lua_State {}
+enum lua_CFunction {}
+
+pub enum Status {
+ OK = 0,
+ YIELD = 1,
+ ERRRUN = 2,
+ ERRSYNTAX = 3,
+ ERRMEM = 4,
+ ERRGCMM = 5,
+ ERRERR = 6,
+}
+
+pub fn newstate() -> *lua_State {
+ lua::luaL_newstate()
+}
+
+pub fn close(state: *lua_State) {
+ lua::lua_close(state)
+}
+
+pub fn openlibs(state: *lua_State) {
+ lua::luaL_openlibs(state)
+}
+
+pub fn loadstring(state: *lua_State, string: &str) -> Status {
+ let status = do str::as_c_str(string) |c_string| {
+ lua::luaL_loadstring(state, c_string)
+ };
+ match status {
+ 0 => OK,
+ 3 => ERRSYNTAX,
+ 4 => ERRMEM,
+ 5 => ERRGCMM,
+ _ => fail ~"Unexpected status in loadstring",
+ }
+}
+
+pub fn call(state: *lua_State, nargs: int, nresults: int) {
+ lua::lua_callk(
+ state,
+ nargs as libc::c_int,
+ nresults as libc::c_int,
+ 0 as libc::c_int,
+ 0 as *lua_CFunction
+ )
+}
+
+extern mod lua {
+ fn luaL_newstate() -> *lua_State;
+ fn lua_close(state: *lua_State);
+ fn luaL_openlibs(state: *lua_State);
+
+ fn luaL_loadstring(
+ state: *lua_State,
+ string: *libc::c_char
+ ) -> libc::c_int;
+ fn lua_callk(
+ state: *lua_State,
+ nargs: libc::c_int,
+ nresults: libc::c_int,
+ ctx: libc::c_int,
+ k: *lua_CFunction
+ );
+}