Skip to content

Commit

Permalink
Minor cleanup of custom generators + basic docs
Browse files Browse the repository at this point in the history
  • Loading branch information
emberian committed Nov 5, 2014
1 parent 460cc51 commit 0e8fa29
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,12 @@ implementations for these APIs.
You will need to manually provide the linkage. For example to use WGL or
OpenGL 1.1 on Windows, you will need to add
`#[link="OpenGL32.lib"] extern {}` somewhere in your code.

### Custom Generators

The `gl_generator` crate is extensible. This is a niche feature useful only in
very rare cases. To create a custom generator, [create a new plugin
crate](http://doc.rust-lang.org/guide-plugin.html#syntax-extensions) which
depends on `gl_generator`. Then, implement the `gl_generator::Generator` trait
and in your plugin registrar, register a function which calls
`gl_generator::generate_bindings` with your custom generator and its name.
8 changes: 4 additions & 4 deletions src/gl_generator/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,14 @@ fn macro_handler(ecx: &mut ExtCtxt, span: Span, tts: &[TokenTree]) -> Box<MacRes

/// Entry point for generating bindings based on a syntax extension invocation.
pub fn generate_bindings(ecx: &mut ExtCtxt, span: Span, tts: &[TokenTree],
custom_generators: Vec<(&str, Box<Generator>)>) -> Box<MacResult+'static> {
generators: Vec<(&str, Box<Generator>)>) -> Box<MacResult+'static> {
// Generator options
let mut api = None::<(Ns, &'static [u8])>;
let mut profile = None::<String>;
let mut version = None::<String>;
let mut generator = None::<Box<Generator>>;
let mut extensions = None::<Vec<String>>;
let mut custom_generators = Some(custom_generators);
let mut generators = Some(generators);

let tts = drop_trailing_comma(tts);

Expand Down Expand Up @@ -255,8 +255,8 @@ pub fn generate_bindings(ecx: &mut ExtCtxt, span: Span, tts: &[TokenTree],
}
match tts {
[&TtToken(span, token::LitStr(gen))] => {
if custom_generators.is_none() { continue; }
for (name, generator_) in custom_generators.take().unwrap().into_iter() {
if generators.is_none() { continue; }
for (name, generator_) in generators.take().unwrap().into_iter() {
if name == gen.as_str() {
generator = Some(generator_);
break;
Expand Down

0 comments on commit 0e8fa29

Please sign in to comment.