These are chat archives for ChaiScript/ChaiScript

18th
Apr 2017
sinadogru
@sinadogru
Apr 18 2017 00:50
@lefticus In my opinion ChaiScript is a brilliant C++ project, it is fun to read the code base and learn new stuff about C++ but often while working with ChaiScript I find myself writing boilerplate code, exposing C++ classes is one example. Do you have any future plan to make exposing one line of code? Thanks for support!
Jason Turner
@lefticus
Apr 18 2017 00:57
Any future plans to make exposing code easier relies on C++ adding reflection support
without that it's virtually impossible
or using something like SWIG to generate the bindings for you
Harish Bhagat
@Wizardo367
Apr 18 2017 13:29

I've had a look at the example you posted but I'm still having an issue. It's an eval error of "Incomplete Class Block" when the sound object is created in script.

class Script
{

auto s = Sound("test.mp3", true);

def Script()
{ 
}

def Start()
{
print("Start");

}

def Update(dt)
{ 
print("Update");
}

def LateUpdate(dt)
{
print("LateUpdate");
}

def Destroy()
{
print("Destroy");
}

}

The way the class is registered is that a static function returns a module from the sound class whenever a new script is created and adds it to the file. The static function is:

chaiscript::ModulePtr Sound::getModule()
{
    // Create module pointer
    chaiscript::ModulePtr module = std::make_shared<chaiscript::Module>();

    // Define type
    module->add(chaiscript::user_type<Sound>(), "Sound");

    // Register base class
    module->add(chaiscript::base_class<Component, Script>());

    // Register class
    chaiscript::utility::add_class<Sound>(*module, "Sound",
    {
        chaiscript::constructor<Sound()>(),
        chaiscript::constructor<Sound(std::string& path, const bool make2D)>(),
        chaiscript::constructor<Sound(const Sound&)>()
    },
    {
        {chaiscript::fun(&Sound::is3D), "is3D"},
        {chaiscript::fun(&Sound::isLooped), "isLooped"},
        {chaiscript::fun(&Sound::isPaused), "isPaused"},
        {chaiscript::fun(&Sound::setPath), "setPath"},
        {chaiscript::fun(&Sound::getPath), "getPath"},
        {chaiscript::fun(&Sound::loop), "loop"},
        {chaiscript::fun(&Sound::pause), "pause"},
        {chaiscript::fun(&Sound::play), "play"},
        {chaiscript::fun(&Sound::playOnce), "playOnce"},
        {chaiscript::fun(&Sound::playLoop), "playLoop"},
        {chaiscript::fun(&Sound::getVolume), "getVolume"},
        {chaiscript::fun(&Sound::setVolume), "setVolume"},
    });

    return module;
}

Any idea what the cause is?

Jason Turner
@lefticus
Apr 18 2017 14:17
You cannot do in class initialization of members in ChaiScript. You need to initialize your s object in the Script() constructor