digitalmars.D - I need runtime reflection
- Gheorghe Gabriel (8/8) Sep 27 2017 Hi,
- Jordan Wilson (7/15) Sep 27 2017 I've used a reflection library called witchcraft which might be
- JN (5/13) Sep 29 2017 Your best bet is to either use a scripting language like Lua
- Gheorghe Gabriel (21/36) Sep 29 2017 Thank you for your answer,
- bitwise (5/7) Sep 29 2017 DLL support for D is currently very spotty. Before investing too
- Gheorghe Gabriel (3/10) Sep 29 2017 So, could you upload a copy of your own reflection module? I want
- bitwise (48/59) Sep 29 2017 I'm reworking how properties/fields are set, and how functions
- bitwise (4/5) Sep 30 2017 Still work to do, but usable.
- Gheorghe Gabriel (8/13) Oct 01 2017 I understand, thank you! :)
- bitwise (8/23) Oct 01 2017 I'm curious to see what you've come up with.
Hi, I have a 3D scene editor. I need my scripts to be dynamically loaded in the scene. How can I do that with D? I know that std.traits only works in compile time. Please, help me Gabriel
Sep 27 2017
On Wednesday, 27 September 2017 at 20:03:27 UTC, Gheorghe Gabriel wrote:Hi, I have a 3D scene editor. I need my scripts to be dynamically loaded in the scene. How can I do that with D? I know that std.traits only works in compile time. Please, help me GabrielI've used a reflection library called witchcraft which might be helpful to you. For script execution, I like LuaD, might be worth checking out also. Jordan
Sep 27 2017
On Wednesday, 27 September 2017 at 20:03:27 UTC, Gheorghe Gabriel wrote:Hi, I have a 3D scene editor. I need my scripts to be dynamically loaded in the scene. How can I do that with D? I know that std.traits only works in compile time. Please, help me GabrielYour best bet is to either use a scripting language like Lua a dll and load them from there.
Sep 29 2017
On Friday, 29 September 2017 at 09:34:26 UTC, JN wrote:On Wednesday, 27 September 2017 at 20:03:27 UTC, Gheorghe Gabriel wrote:Thank you for your answer, This is a script example: ---------------------------- module game.player; import engine; class Player : Actor { this(string name) { super(name) } ~this() {} void jump() { ... } Editable("Slider")("min = 0; max = 5;") ubyte lives = 5; } ---------------------------- If i compile this script to a .dll then pleyer object can be dragged and dropped into the scene? Do yout think that after the final LDC Android build, the game will work properly on Android? (because of .dll scripts) GabrielHi, I have a 3D scene editor. I need my scripts to be dynamically loaded in the scene. How can I do that with D? I know that std.traits only works in compile time. Please, help me GabrielYour best bet is to either use a scripting language like Lua to a dll and load them from there.
Sep 29 2017
On Friday, 29 September 2017 at 11:05:00 UTC, Gheorghe Gabriel wrote:[...] If i compile this script to a .dllDLL support for D is currently very spotty. Before investing too much time, I would suggest confirming that DLLs are even properly supported for your target platform at all.
Sep 29 2017
On Friday, 29 September 2017 at 16:24:32 UTC, bitwise wrote:On Friday, 29 September 2017 at 11:05:00 UTC, Gheorghe Gabriel wrote:So, could you upload a copy of your own reflection module? I want to try it and then I will send you my feedback.[...] If i compile this script to a .dllDLL support for D is currently very spotty. Before investing too much time, I would suggest confirming that DLLs are even properly supported for your target platform at all.
Sep 29 2017
On Friday, 29 September 2017 at 16:40:38 UTC, Gheorghe Gabriel wrote:On Friday, 29 September 2017 at 16:24:32 UTC, bitwise wrote:I'm reworking how properties/fields are set, and how functions are called. I'm not sure how long it will take. I'll throw a copy up when it's done. Simple reflection is not that hard though: ` ClassReflection[string] _reflections; abstract class ClassReflection { Object create() const; string name() const; } class ClassReflectionImpl(T) : ClassReflection { import std.traits : fullyQualifiedName; static this() { _reflections[fullyQualifiedName!T] = new typeof(this); } override Object create() const { return new T; } override string name() const { return T.stringof; } } template registerClass(T) { alias registerClass = ClassReflectionImpl!T; } export extern(C) ClassReflection reflectionOf(string name) { ClassReflection* pRefl = name in _reflections; return pRefl ? *pRefl : null; } class Player { void speak() { writeln("hello world"); } } alias registration = registerClass!Player; int main(string[] argv) { ClassReflection playerRefl = reflectionOf("main.Player"); ClassReflection missingRefl = reflectionOf("main.MissingClass"); assert(playerRefl !is null); assert(missingRefl is null); Player player = cast(Player)playerRefl.create(); assert(player !is null); player.speak(); return 0; } ` You can use __traits and std.traits to build whatever you need into ClassReflection.On Friday, 29 September 2017 at 11:05:00 UTC, Gheorghe Gabriel wrote:So, could you upload a copy of your own reflection module? I want to try it and then I will send you my feedback.[...] If i compile this script to a .dllDLL support for D is currently very spotty. Before investing too much time, I would suggest confirming that DLLs are even properly supported for your target platform at all.
Sep 29 2017
On Friday, 29 September 2017 at 16:40:38 UTC, Gheorghe Gabriel wrote:[...]Still work to do, but usable. https://github.com/nicolasjinchereau/d-reflection
Sep 30 2017
On Saturday, 30 September 2017 at 19:06:20 UTC, bitwise wrote:On Friday, 29 September 2017 at 16:40:38 UTC, Gheorghe Gabriel wrote:I understand, thank you! :) I have created another scripting model (compiled, not interpreted) for the graphics engine, which is better than the runtime reflection (it has only one disadvantage and more advantages over it). I cannot wait until the engine is finished, so that I will be able to show it to the public. Gabriel[...]Still work to do, but usable. https://github.com/nicolasjinchereau/d-reflection
Oct 01 2017
On Sunday, 1 October 2017 at 15:53:57 UTC, Gheorghe Gabriel wrote:On Saturday, 30 September 2017 at 19:06:20 UTC, bitwise wrote:I'm curious to see what you've come up with. There are certain problems that can't really be overcome with a compile time approach, like generically passing things across DLL boundaries, or modifying/referencing things at design-time in an editor. You could generate some generic wrapper/interface at compile time, but that would basically be the same as run-time reflection at that point.On Friday, 29 September 2017 at 16:40:38 UTC, Gheorghe Gabriel wrote:I understand, thank you! :) I have created another scripting model (compiled, not interpreted) for the graphics engine, which is better than the runtime reflection (it has only one disadvantage and more advantages over it). I cannot wait until the engine is finished, so that I will be able to show it to the public. Gabriel[...]Still work to do, but usable. https://github.com/nicolasjinchereau/d-reflection
Oct 01 2017