These are chat archives for ChaiScript/ChaiScript

1st
Mar 2018
Tharindu Mathew
@mackiem
Mar 01 2018 17:57
are there capabilities in chaiscript to get all functions in a class? ex: chai.give_all_methods("foo"); google does not seem to show anything
Jason Turner
@lefticus
Mar 01 2018 18:38
the problem is that member functions / methods don't really exist in chaiscript
everything is a free function that happens to take the 1st parameter of a given type
Tharindu Mathew
@mackiem
Mar 01 2018 19:44
ok, so anyway i can do something like get all functions of a namespace or something similiar? I want to allow the definition of some n number functions by a user, and execute those functions as callbacks. I'm using classes as a hack of grouping those functions in some way, but maybe there's a better way
ok, i can simply use files as a grouping function, can i get all functions defined?
i don't know the function names in advance, hence the requirement
Jason Turner
@lefticus
Mar 01 2018 19:54
I suggest you have you user provide them all in an object, like a vector
fun() {
var funcs = [];
funcs.push_back(somecallback);
};
Then you would call callbacks = eval_file("some_filename")();
so you would have them write a file that defines a function
then you call that function and store the results
No0n3Left
@No0n3Left
Mar 01 2018 20:11
How would I store a way to call a chaiscript function in C++? Is there a way to get some type of std::function from it, or would it be better just to store it as a string and add the arguments when it was called?
Jason Turner
@lefticus
Mar 01 2018 20:14
Unless I'm misunderstanding - this is one of the main features of chaiscript!
auto func = chai.eval<std::function<int (int, int)>>("fun(int x, int y) { return x + y; }");
in c++
return func(3,2) // returns 5 via call into chaiscript
Tharindu Mathew
@mackiem
Mar 01 2018 20:24
ok, that seems a good workaround, thanks @lefticus
No0n3Left
@No0n3Left
Mar 01 2018 20:24
I’m trying to keep a unordered_map using a string for the key in C++, but where I can have a function of any type (well, return value for all will be void, but different argument types).
That may be more of a C++ thing than chaiscript thing though
Jason Turner
@lefticus
Mar 01 2018 20:32
You can keep them as a strongly typed function, or as a Boxed_Value in c++. In fact, a ChaiScript map is simply std::map<std::string, chaiscript::Boxed_Value> so this map could be shared directly with C++
No0n3Left
@No0n3Left
Mar 01 2018 20:35
Ok, so, could I call a Boxed_Value containing a function or would I have to explicitly cast it almost like std::any?
Jason Turner
@lefticus
Mar 01 2018 20:37
you have to cast it to the type of function you expect it to be
or pass it back into chaiscript and attempt to execute it as a function there
No0n3Left
@No0n3Left
Mar 01 2018 20:45
Ok, what I may do is just store a string with the name of the function in chaiscript, because I don’t really ever need to have C++ functions in the callbacks. Then I can just make a string with the name and argument values and call that.
Tharindu Mathew
@mackiem
Mar 01 2018 21:20
so, when i include chairscript chai in a header file as a member variable, my build failed with a bunch of warninings from chaiscript, and a resulting syntax error
warning C4602: #pragma pop_macro : 'min' no previous #pragma push_macro for this identifier
any idea?
Arthur Brainville
@Ybalrid
Mar 01 2018 21:21
On windows?
Tharindu Mathew
@mackiem
Mar 01 2018 21:21
yeah
int maxX = std::max(vt1.x, std::max(vt2.x, vt3.x));
the syntax error comes on points where i have used std::max
or min
Arthur Brainville
@Ybalrid
Mar 01 2018 21:21
try to do a #define NOMINMAX before including <Windows.h> ?
There's a crappy macro in the Windows headers taht define min() and max() in the preprocessor
Tharindu Mathew
@mackiem
Mar 01 2018 21:22
hmmm, i'm using qt so I don't include windows.h directly
maybe on top of main will work?
Arthur Brainville
@Ybalrid
Mar 01 2018 21:22
Well, try to stick that on top of the file that generate the error?
Tharindu Mathew
@mackiem
Mar 01 2018 21:25
sorry for that dumb question. It built! With like a gazillion warning about pragma pop_macro
Arthur Brainville
@Ybalrid
Mar 01 2018 21:26
Something strange is going on. We can all blame Microsoft for adding theses ** macros in the first place ;-)
Tharindu Mathew
@mackiem
Mar 01 2018 21:27
if only openoffice/libreoffice was decent, and nvidia cards worked, and etc, etc we could all switch to linux
Arthur Brainville
@Ybalrid
Mar 01 2018 21:28
official Nvidia drivers on Linux aren't bad at all to be honest
well, they mess some little things up because they doesn't respect some convention for X11
But if what you want to do is have good 3D performance, they do work just fine nowadays
Tharindu Mathew
@mackiem
Mar 01 2018 21:32
i have an old thinkpad which has trouble with linux, sigh. cuda refuses to work even though the card is fine. I know linux is not to blame for this, but oh well.
Arthur Brainville
@Ybalrid
Mar 01 2018 21:33
I don't really know about the CUDA support
I don't know a lot about GPGPU programming in general actually ^^"
Tharindu Mathew
@mackiem
Mar 01 2018 21:34
I'm trying to use chaiscript to do some graphics and some cuda stuff, so I care about those things a lot
Arthur Brainville
@Ybalrid
Mar 01 2018 21:35
I use ChaiScript as the scripting interface inside a game engine designed for VR content
Tharindu Mathew
@mackiem
Mar 01 2018 21:36
ah that's cool, what's the engine?
Arthur Brainville
@Ybalrid
Mar 01 2018 21:37
It's mostly a lot of glue code to make OGRE (3D renderer), Bullet (physics simulation), OpenAL (audio spatialization) and a bunch of other stuff together
the chaiscript usage in this is some not that pretty code
The idea is that you can attach "behavior script" to game objects, a bit like you do with Unity3D
So, I have files that I expect to have a "class" defined in ChaiScript with a certain name, and that will define a few methods, optionally more
Tharindu Mathew
@mackiem
Mar 01 2018 21:39
right, i understand, basically trying to support the entitiy component system
pretty cool stuff
how would u say the support is for oculus, etc. on linux
Arthur Brainville
@Ybalrid
Mar 01 2018 21:40
Yeah, that's the basic idea
Pretty bad for Oculus
no official support. Some people are hacking together
there's I think a Free Open Source stuff that support "rotational" tracking
so you can turn your head but not move around
HTC-Vive is based on SteamVR
And currently, if you can Run Steam, and have a supported GPU, it will work
there's others one on the market. An initiative called "OSVR" (Open Source VR) has good linux support
Tharindu Mathew
@mackiem
Mar 01 2018 21:42
valve has a vested interest in making things work on linux... that's good news
Arthur Brainville
@Ybalrid
Mar 01 2018 21:42
Yeah, and they are fixing some of the problems you encounter if you want to distribute software for Linux in binary form
When you install steam, you install a "common runtime"
where you will have a knwon version of the C standard library, of SDL, and of a bunch of other "core" libraries that you generally use for game programming on Linux
Tharindu Mathew
@mackiem
Mar 01 2018 21:44
it only took one year for the nintendo switch to take off
Arthur Brainville
@Ybalrid
Mar 01 2018 21:44
So, you don't have to be sure that it will work on each particular version of each distros. You know that the dynamic libraries that will be loaded are the versions you expect
Tharindu Mathew
@mackiem
Mar 01 2018 21:44
if linux has 1 or 2 killer stuff, everyone will be installing linux before you say "oh wow"
Arthur Brainville
@Ybalrid
Mar 01 2018 21:45
Well, everybody was saying this when they released the whole "SteamOS" thing, but the reality is, there's a lot of games that will not run under linux...
And it would require some work from developers to port them. Generally because they use DirectX for everything
You have a good feature parity with SDL+OpenGL, and doing that switch makes you code cross platform (there's way more stuff the SDL has to offer that people don't thing about. You can create thread/mutexes from the SDL in a cross platform way, you can load dynamic lib via it, etc...)
when you write cross platform code, it generally endup in some ugly #ifdef _WIN32 #elif __linux__ #endif hell
Anyway, conversation drifted quite far from ChaiScript :stuck_out_tongue:
Tharindu Mathew
@mackiem
Mar 01 2018 21:50
hehe yeah, are we allowed to do that? :D
Arthur Brainville
@Ybalrid
Mar 01 2018 21:50
It's intended to be a support chat for ChaiScript ;-)
Tharindu Mathew
@mackiem
Mar 01 2018 21:52
so chaiscript question, how do i instantiate a c++ object from chaiscript
I want to create a glm::vec3(), but I'm runnning into some trouble
chai.add(chaiscript::fun(glm::vec3()), "vec3");
ends up with some errors
chai.add(chaiscript::fun(glm::vec3), "vec3");
does not work either
Arthur Brainville
@Ybalrid
Mar 01 2018 21:55
chai.add(chaiscript::constructor<ClassName(Args)>(), "ClassName")
this is how you give a constructor to ChaiScript
Tharindu Mathew
@mackiem
Mar 01 2018 21:56
ok, right, i just tried chai.add(chaiscript::user_type<glm::vec3>(), "vec3");
Arthur Brainville
@Ybalrid
Mar 01 2018 21:56
use chaiscript::constructor<>
and insidte the () inside the angle brackets in my examble you put the argument this overload of the constructor accept
yeah, you need to register each overload you want to expose one by one AFAIK
user_type is usefull for inheritance, but not required
Tharindu Mathew
@mackiem
Mar 01 2018 22:11
cool, that's what i needed, thanks!
Arthur Brainville
@Ybalrid
Mar 01 2018 22:11
:thumbsup:
Jason Turner
@lefticus
Mar 01 2018 23:35
For those who care about the details: constructors are not functions in C++
that's why it's impossible to add it like you wanted to, even if there was only one constructor
and why we have to have the constructor<> wrapper
Arthur Brainville
@Ybalrid
Mar 01 2018 23:37
@lefticus I haven't looked at the detail, but now that you say this, the fact that they don't have a return type, and are only there to initialize the object's content, it makes sense