Last active
July 26, 2018 00:21
-
-
Save notriddle/7337c5aeb6d31b1ce978a123dda66f72 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://rust-lang.org/ | |
use std::ffi::CStr; | |
use std::os::raw::{c_char, c_int}; | |
use std::slice; | |
use lua_sys::lua_State; | |
unsafe extern "C" fn runargs(l: *mut lua_State, argv: *mut *mut c_char, n: c_int) -> c_int { | |
// slices can use normal [] access, while pointers have to use the .offset method | |
// so convert the pointer to a slice, because otherwise this'll be 99% .offset(i).deref().offset(0).deref() | |
let args = &slice::from_raw_parts(argv, n)[1..]; | |
let mut iter = args.iter().cloned().map(CStr::from_ptr); | |
while let Some(arg) = iter.next() { | |
let option = arg[1]; | |
debug_assert_eq!(arg[0], b'-'); // already checked | |
if option == b'e' || option == b'l' { | |
let mut extra = &arg[2..]; | |
if extra.len() == 0 { | |
extra = iter.next().expect("missing parameter"); | |
} | |
let status = if option == b'e' { | |
dostring(l, extra, "=(command line)") | |
} else { | |
dolibrary(l, extra) | |
}; | |
if status != LUA_OK { | |
return 0; | |
} | |
} | |
} | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment