Code Monkey home page Code Monkey logo

meta's Introduction

Hi there, I'm skypjack ๐Ÿ‘‹

zak

Despite what you may have thought, I'm not Zak. Iโ€™m Michele Caini, software developer from Florence, Italy.
I'm also a freelancer, I work mainly remotely and in my free time I dedicate myself to some open source projects such as EnTT.
Oh... and I'm a father too, madly in love with my wife and son who always support me! ๐Ÿ˜

Something about me:

  • ๐Ÿ”ญ Iโ€™m currently working on Minecraft, thanks to the Microsoft Mojang Studios ๐Ÿ˜ฒ and I'm very grateful for this opportunity.
  • ๐Ÿ’ป I'm a freelancer. Don't hesitate to contact me if you want to offer a collaboration. Fond of C++, gaming and high perf.
  • ๐Ÿ“ซ Check the links in my profile. Feel free to ping me to say hello, introduce yourself and have a chat. ๐Ÿ™‚

๐Ÿ™ Support me if you like ...

Everything you can find on my GitHub profile or on my blog I do in my spare time, without any kind of income.
If you want to help me by contributing or otherwise supporting me, you can take a look at my sponsorship page.

Twitter: scaipgec GitHub skypjack

meta's People

Contributors

gamecentric avatar skypjack avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

meta's Issues

Is it possible to use library for [de]serialization?

As I see, all meta mapping performed in integers. So, after meta is created, I could only test if member exist, not iterate through all mapped methods and save values (Imagine struct => json)
Am I wrong or library is not created for this?

Please tell what I'm missing

Return values by reference

First of all: great work! The interface provided by this library is amazing! I am considering integrating it into my toy c++ game engine to provide reflection for serialization of the engine components.

However, it seems that functions that return by-reference are not supported and will always return a copy. See the following snippet:

    struct MyValue {
        int value = 0;
        int& get() {
            return value;
        }
    };

    meta::reflect<MyValue>("MyValue")
            .func<&MyValue::get>("get");

    MyValue value;
    meta::any i = meta::resolve("MyValue")
            .func("get")
            .invoke(value);
    value.value = 1;
    std::cout << i.cast<int>() << std::endl;

The output would be expected to be 1. This code, however, outputs 0. This both unintuitive and significantly limits the possibilities of the library:

  • you can't return non-copyable types by reference
  • you can't mutate any returned member

Serialization of meta::any

Hi @skypjack,
Thank you for the library, it is great!

I just couldn't figure out a way to serialize meta::any. May be somehow access the underlying data and extract it?

Something like:

// **** Init
MyType obj;
meta::reflect<MyType >(hash("MyType "))
       .data<&MyType::some_variable>(hash("some_variable"));

auto data = meta::resolve<MyType>().data(hash("some_variable"));

// **** Write
std::cout << data(&obj).name() << ":" << data(&obj).toString();

// **** Read
std::string str; // or const char * or something else readable from file
data.set(&obj, meta::any{str});

Do you think it can be possible?

MD DLL

Hello
I was testing meta.hpp in MD dll, but it was implemented as static inline, so I couldn't use it as is. I changed that code and it seems to work fine. Do you have any advice for me?

Or, if someone else is doing something similar, I'd love to help.

AutoGen

I wanted to make it like UnrealEngine, I modified HeaderParser to automatically generate generated.h code, and register the class in Reflection function.

The Reflection function is being called for all classes registered within a specific dll, but since meta.hpp is implemented as static inline, a separate instance is created for each dll.

Example

CORE_API is dllexport, dllimport

Example2

all internal::type_info<>::type -> *meta::internal::GetLastNode()
I changed it to save it to unordered_map in a specific dll memory and it worked.

I haven't tested every function and can't guarantee its operation. However, I think you can approach it in the same way as above.

Documentation of properties could be improved

There are a couple of issues in the documentation of properties. First, the following example is provided:

meta::reflect<my_type>("reflected", std::make_pair("tooltip", "message"));

In this case, the first element of the pair, which is used to identify the property, will decay to a const char* and then stored in a meta::any object. Subsequently, properties are found applying operator == on meta::any instances, which is implemented by comparing the value of the pointers. This is a problem, because string literals potentially all have unique addresses, so the property cannot be portably and reliably be retrieved at later time.

The retrieval example is also problematic:

meta::prop prop = meta::resolve<my_type>().prop("tooltip");

since this doesn't compile on at least one compiler (Visual Studio 2019). The problem is that in this case the literal string does not decay to a pointer and apparently the meta::any constructor is not able to accept a const char (&)[8].

These two issues could be solved by using std::string as the type of the property key. However, the use case described in the documentation seems legit and useful, so if that's the intent, we should fix the code instead so that it works as described. There may be multiple ways to achieve this, for example, we could add the following non-template overload of the meta::type::prop method:

       const auto* curr = internal::find_if<&internal::type_node::prop>([key](auto* candidate) {
          auto ptr = candidate->key().try_cast<const char*>();
          return ptr && strcmp(*ptr, key) == 0;
       }, node);

       return curr ? curr->clazz() : meta::prop{};
    }```

Support to unregister a type

Hi
I'm using the library in the context of a plugin system which support hot reloading.
Each plugin can register new types. In the context of a hot reload, the host unloads the previous version of the plugin and loads the new one which can register a new version of the type.
I need to unregister the original type to be able to register the potentially new version of the type.

Right now I wrote a small function which works for me

template<typename Type>
bool unregister() noexcept {
  auto type_to_unregister = meta::internal::type_info<Type>::resolve();
  auto* addr_t = &meta::internal::info_node<>::type;
  while( addr_t && *addr_t ) {
    auto t = *addr_t;
    if( t == type_to_unregister ) {
      *addr_t = t->next;
      return true;
    }
    addr_t = (meta::internal::type_node **) &t->next;
    t = t->next;
  }
  return false;
}

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.