Git Product home page Git Product logo

rlua-table-derive's Introduction

rlua-table-derive

This crate provides a custom derive for a FromLuaTable trait

To derive just add FromLuaTable to the derive list for a struct. Default must be implemented for a type to use this macro.

An example usage can be found in the examples directory. I have copied it here for convenience:

#[macro_use] extern crate rlua_table_derive;
extern crate rlua;


#[derive(Default, Debug, Clone, FromLuaTable)]
pub struct Thing{
    x: f32,
    y: f32,

    name: String,
}

trait FromLuaTable {
    fn from_lua_table(table: &rlua::Table) -> Self;
}

const LUA_STRING: &str = "
thing = {
    x=2,
    name='john',
}
";

fn main() {
    let lua = rlua::Lua::new();
    lua.eval::<()>(LUA_STRING, Some("baked in")).unwrap();

    let default = Thing::default();

    let table = lua.globals().get("thing").unwrap();
    let from_lua = Thing::from_lua_table(&table);

    print!("Default: {:?}\n", default);
    print!("From lua: {:?}\n", from_lua);
}

rlua-table-derive's People

Contributors

zwparchman avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.