Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

lambda captured #404

Open
k1epic opened this issue Jan 13, 2023 · 1 comment
Open

lambda captured #404

k1epic opened this issue Jan 13, 2023 · 1 comment

Comments

@k1epic
Copy link

k1epic commented Jan 13, 2023

// c++20    vs2019 (v142) /////////////////////////////

struct test
{
	int a;

	void init ( const std::string& name, gravity_vm * vm)
	{

		gravity_class_t* class_t      = gravity_class_new_pair(NULL, name.c_str(), NULL, 0, 0);
		gravity_class_t* class_t_meta = gravity_class_get_meta(class_t);

                        // [&a]
                        // [&]
		auto _fn = [this](gravity_vm* vm, gravity_value_t* args, uint16_t nargs, uint32_t rindex)->bool
		{
			int b = a + 10;
			return true;
		};

                // NEW_CLOSURE_VALUE
	        // static gravity_value_t a
	        // {
		//    .isa = gravity_class_closure,
		//    .p   = (gravity_object_t*)gravity_closure_new(NULL, gravity_function_new_internal(NULL,NULL,  (_fn) ,  0))
	        // };

		gravity_class_bind(class_t_meta, "fn_example", NEW_CLOSURE_VALUE(_fn));

		gravity_vm_setvalue(vm, name.c_str(), VALUE_FROM_OBJECT(class_t));
	}
};

//  error  /////////////////////////////

// error C2664: 'gravity_function_t *gravity_function_new_internal(gravity_vm *,const char *,gravity_c_internal,uint16_t)' :  
// cannot convert argument 3 from 'test::init::<lambda_1>' to 'gravity_c_internal'
// No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called


@marcobambini
Copy link
Owner

marcobambini commented Jan 13, 2023

@k1epic it is a C++ compiler-generated error and not a Gravity error.
I am not sure I can help you with this issue.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants