These are chat archives for ChaiScript/ChaiScript

19th
Mar 2015
Andreas Reischuck
@arBmind
Mar 19 2015 16:40

The conversions work great. But now I try to get the index operator right.
What is the difference between:

char.add(chaiscript::fun<QVariant (const QVariant*, const std::string&)>([](const QVariant* v, const std::string& key){ ... })), "[]");

and

char.add(chaiscript::fun(std::function<QVariant (const QVariant*, const std::string&)>([](const QVariant* v, const std::string& key){ ... }))), "[]");

But my script "variant.member" does not trigger either of these.
I guess I use the wrong function name here.

I found both variants in the STL and bootstrap
Jason Turner
@lefticus
Mar 19 2015 16:48
One might simply be older than the other, but without looking up the exact context, it's probably dependent on needing to work around some issue with the STL function I was wrapping having multiple overloads. But those two should pretty much accomplish the same thing
if you're trying to wrap an index operator, you'd need to use it like you would in C++:
variant["value"]
but I don't see an [] operator on QVariant so I'm not sure what you're aiming for
Andreas Reischuck
@arBmind
Mar 19 2015 16:50
QVariant might hold a QVariantHash or a QObject... both are associative
I looked up the dot evaluation... It seems that you don't support a direct invocation for that
qObject.boolValue
results in calling boolValue on my QVariant that holds a QObject
Jason Turner
@lefticus
Mar 19 2015 16:55
so, what you want is to be able to do something like:
Andreas Reischuck
@arBmind
Mar 19 2015 16:56
In Javascript qObject.boolValue and qObject['boolValue']is the same... In ChaiScript it seems to be two different things like in C++
Jason Turner
@lefticus
Mar 19 2015 16:57
Yes, that's true
that would be a distinct difference between the two languages
I've yet to come up with a really good story for how to implement something like that in ChaiScript, without killing performance
Andreas Reischuck
@arBmind
Mar 19 2015 17:01
You do not use any kind of dot property access ?
Jason Turner
@lefticus
Mar 19 2015 17:02
C++ types don't have 'properties' at all
only what functions you expose
unless I misunderstand your question
you definitely cannot do: obj.someRandomUndefinedName = 3
Andreas Reischuck
@arBmind
Mar 19 2015 17:03
ok, I see
That's really a bummer :worried:
rect.height = 30
Jason Turner
@lefticus
Mar 19 2015 17:09
That only works for dynamic types that are created inside of ChaiScript (ie, not types defined in C++ then exposed). You have to pre-define the attr, as you see, then it creates a function called "height" that takes a type of "rect" and returns a reference to the contained object
you could emulate something like that, let me think for a second
Andreas Reischuck
@arBmind
Mar 19 2015 17:11
If you would add something like the Ruby "undefined_method" thing, that would help :)
Jason Turner
@lefticus
Mar 19 2015 17:12
var m = Map()
def heightImpl(MyObjectType o, Map m)
{
  return m["height"]
}

var height = bind(heightImpl, _, m)

// then:

myObject.height = 2
that's COMPLETELY undested
untested
but it should work
so explain what you mean by the undefined_method support
I just made a correction to that heightImpl name
Andreas Reischuck
@arBmind
Mar 19 2015 17:13
If ruby does not find the method on an object, it calls that method with the name all arguments
Jason Turner
@lefticus
Mar 19 2015 17:14
ok, let's talk about that for a sec
so it'd be a special function like:
undefined_method(MyObjectType &obj, const std::string &functionName, const std::vector<Boxed_Value> &t_bv)
so if I did:
Andreas Reischuck
@arBmind
Mar 19 2015 17:15
yes...
Jason Turner
@lefticus
Mar 19 2015 17:15
myObj.newName(1)
it would do: undefined_method(myObj, "newName", <vector with 1>)
Andreas Reischuck
@arBmind
Mar 19 2015 17:17
excactly
Jason Turner
@lefticus
Mar 19 2015 17:17
and it would be strongly typed, not global
on the first param
Andreas Reischuck
@arBmind
Mar 19 2015 17:17
sure
Jason Turner
@lefticus
Mar 19 2015 17:17
that's probably doable
I have to think about where I would hook that in
Andreas Reischuck
@arBmind
Mar 19 2015 17:18
Instead of giving up the method dispatch you try to invoke this "meta" method
Jason Turner
@lefticus
Mar 19 2015 17:18
yeah
Andreas Reischuck
@arBmind
Mar 19 2015 17:20
It's called method_missing in Ruby
Jason Turner
@lefticus
Mar 19 2015 17:21
so, I'd have to hook it in here:
the problem is that I don't know the name of the function I was trying to call right there
that's can be changed
well, I need to do some paid work right now, but I'll ponder it
unless you happen to know a company that would like to sponsor some updates to chaiscript ;)
Andreas Reischuck
@arBmind
Mar 19 2015 17:24
no, sorry... I have to beg to try chaiscript here
I like most of the style... very powerful :+1:
Jason Turner
@lefticus
Mar 19 2015 17:27
Thanks. We aimed for simple and flexible
in a doesn't-get-in-your-way kind of philosophy
if you find some specific thing (performance, memory usage, some bug, whatever) that would keep your group from implementing chaiscript, let me know and I'll try to work with you to get it sorted out
Andreas Reischuck
@arBmind
Mar 19 2015 17:32
Thank you for your welcoming support
Jason Turner
@lefticus
Mar 19 2015 17:48
is it possible to ask to what end you are using chaiscript? you want users to be able to provide scripts for your application, or you want to reduce the need to recompile, or ...?
Andreas Reischuck
@arBmind
Mar 19 2015 17:56
I try to replace QScript... In the hope of faster interop
I have added the method_missing feature... works great here :D
17 passed, 9 failed making progress...
Jason Turner
@lefticus
Mar 19 2015 18:11
wow that was fast
please share your implementation
Andreas Reischuck
@arBmind
Mar 19 2015 18:33
The a < b ? a : boperator is not supported?
Jason Turner
@lefticus
Mar 19 2015 18:56
should be
yeah, it's in there
works for me. Only problem I could see is if your a < b operator is not defined for some reason