Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Gibbon99
@Gibbon99

Hi - I've got an issue that I don't understand - hoping to get some insight into what I am doing wrong. I have a chai script with two functions - both exactly the same, I can call the first one fine, but the second one silently fails. I run .eval on the script first, then have a function containing this line "chaiInstance.eval<std::function<void ()>>(functionName);" - it only seems to work on the one function call ie: chai_runFunction("scriptFunc"); - and does nothing calling "chai_runFunction("printFromScript");". this is the script: def scriptFunc()
{
testGlobalVar = 555;
}

def printFromScript()
{
testGlobalVar = 9999;
}

Germán Diago
@germandiagogomez
Hello. I have been using ChaiScript for a while.
I did not find any problem with its speed for my use cases
but I am still wondering
if a speed boost could be achieved
by
making all the methods, etc.
being resolved in a different way
I think that currently, ChaiScript is using strings
for things that are immutable most of the time (method names, etc.)
wouldn't it be more effective to use some kind of immutable string and/or hashing for method resolution? Not sure, though, if this can be done. I do not know the design deeply
As commented, for my use cases speed has not been a problem, though speed is something that is always good to have, specially in games, since the more speed you have, the more scripted code you can do
My real pain point (and this was a real one, not in theory) is the lack of some kind of stackful coroutines compared to Lua and Python.
Martin Chang
@marty1885
I fully agree that compiling ChaiScript is show. (It's my main problem with it)
@germandiagogomez Before C++20 get there you could try zapcc as your compiler. It shoule be way faser.
Germán Diago
@germandiagogomez
No, my complain was not about compile-times actually @marty1885
Germán Diago
@germandiagogomez
Hello everyone again. Would like to know... is it possible to invoke a function from a script that creates a std::thread? It seems to crash in my setup.
Germán Diago
@germandiagogomez
the error was somewhere else :)
vocaviking
@vocaviking
Hi, I'm trying to import chaiscript using cmake, but I can't get the header files to work properly. Right now I'm doing it this way:
cmake_minimum_required(VERSION 3.1...3.11)
project(ace VERSION 5.0.0)
...
add_subdirectory(lib/ChaiScript/)
target_link_libraries(ace PRIVATE chaiscript)
What do I have to do to make this compile?
Arthur Brainville
@Ybalrid
I use either include_directoires or target_include_directories for Chai. As it’s just a folder with a bunch of headers. Therés nothing to link against
« Link libraries » functions are for linking to .a, .lib, .so filles to your target. Nothing to do with headers.
vocaviking
@vocaviking
Sure. However, that's the recommendation I found for including proper cmake projects... add_subdirectory and link against it
This helps you to include chaiscript into several projects depending on it, without duplicating the code. (Something I actually would need.)
StanEpp
@StanEpp

I do it in my project like this:
Add an external_project
https://github.com/StanEpp/ChaiDwarfs/blob/master/deps/CMakeLists.txt#L221

Just add it as a dependency to the project
https://github.com/StanEpp/ChaiDwarfs/blob/master/CMakeLists.txt#L115

As @Ybalrid already said there's nothing to link against. You just include the header files and are good to go.

I hope the code helps. Unfortunately I haven't touched the project in a while
Oliver Dain
@oliverdain
Hey - just posted a question on the forums (http://discourse.chaiscript.com/t/chaiscript-array-of-objects-without-copy-constructor/415) and then discovered there's a chat channel too! Hoping I can get a quicker answer here as I'm kinda stuck right now. Any help would be greatly appreciated.
vocaviking
@vocaviking
@StanEpp This part I did using git submodules, it works fine.
vocaviking
@vocaviking

My problem is, that I have something like:

ace/
    lib/
        chaiscript/
        spdlog/
        libA/  --> uses chaiscript and spdlog
        libB/  --> uses chaiscript and spdlog
    src/
        main.cpp  --> uses libA and libB
    CMakeLists.txt

How can I do this using cmake? In the case of other header-only libraries like spdlog, I simply write the following project file:

    cmake_minimum_required(VERSION 3.1...3.11)
    project(ace VERSION 5.0.0)
    add_subdirectory(lib/spdlog/)
    target_link_libraries(ace PRIVATE libA)
    target_link_libraries(ace PRIVATE libB)

And inside the libraries I have:

    cmake_minimum_required(VERSION 3.1...3.11)
    project(libA VERSION 1.0.0)
    target_link_libraries(libA PRIVATE spdlog)
Rob Loach
@RobLoach
Having a CMakeLists.txt for each folder makes your life easier. I hope to clean up some of the cmake build system in extras as an example.
vocaviking
@vocaviking
That's what I did... Writing a custom CMakeLists.txt for Chaiscript. I would like to make a pull request, but I don't really know how to replace the existing one...
Arthur Brainville
@Ybalrid
Chaiscript being trader only. I never feeler the need of having to get CMake to find it i generally just set it as one of the include directories. Either on the cmake target, or even globally. I either have it copied somewhere, or included via a git submodule
Rich Henry
@phaistos
is the any example of returning a std::vector<int>, particularly what bindings are required?
im getting a dispatch error when i try to call .size() on it
Rob Loach
@RobLoach
@phaistos Might have to let ChaiScript know about the vector type?
chai.add(bootstrap::standard_library::vector_type<std::vector<int>>("VectorInt"));
Addison Schuhardt
@aschuhardt

@RubenReijers yes it does. But it was only added to the develop branch recently. You can do the following when TerrainType is an enum class:

chaiscript::ModulePtr m = chaiscript::ModulePtr(new chaiscript::Module());
chaiscript::utility::add_class<TerrainType>(*m, 
  "TerrainType", 
  { { TerrainType::SOIL, "SOIL" },
    {TerrainType::PASSABLE, "PASSABLE"},
    { TerrainType::STONE, "STONE" }
  }
);

Is it still possible to use enum classes this way in the current development branch?

I've tried this same method as follows:
  auto key_module = std::make_shared<chaiscript::Module>();
  chaiscript::utility::add_class<Key>(
      *key_module, "Key",
      {
          {Key::N0, "KEY_N0"},
          {Key::N1, "KEY_N1"},
          {Key::N2, "KEY_N2"},
          {Key::N3, "KEY_N3"},
          {Key::N4, "KEY_N4"},
...
I'm not sure how I'm supposed to access these values however.
I've tried
  var k = Key();
  print(k.KEY_N0);
But I get the error message terminate called after throwing an instance of 'chaiscript::exception::eval_error' what(): Error: "Error with function dispatch for function 'to_string'" With parameters: (Key).()
trying to access the class's attr by value var x = k.KEY_N0; throws another error
Error: "'KEY_N0' is not a function."
Maybe I'm misunderstanding what the add_class utility is supposed to be doing?
Addison Schuhardt
@aschuhardt
var k = Key.KEY_N0 throws this error:
Error: "Error with function dispatch for function 'KEY_N0'" With parameters: (const Function).(string)
What am I missing?
Addison Schuhardt
@aschuhardt
Welp. Figured it out. It adds global(?) constants. This works:
var k = KEY_N0;