summaryrefslogtreecommitdiffstats
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
downloadrust-lua-bd93ba9d4419899694f16317d288125762dcaa33.tar.gz
rust-lua-bd93ba9d4419899694f16317d288125762dcaa33.zip
initial commit
-rw-r--r--.gitignore2
-rw-r--r--lua.rs69
-rw-r--r--main.rs9
3 files changed, 80 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..36cdcf2
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+main
+*.so
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
+ );
+}
diff --git a/main.rs b/main.rs
new file mode 100644
index 0000000..1e50e6f
--- /dev/null
+++ b/main.rs
@@ -0,0 +1,9 @@
+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);
+}