sol2 icon indicating copy to clipboard operation
sol2 copied to clipboard

How to eliminate the C Closure created during usertype construction

Open ianfor opened this issue 8 months ago • 0 comments

//c++
module.new_usertype<Vector3>(
"Vector3",
sol::constructors<Vector3(float, float, float)>(),
"add",
&Vector3::add, 
...);


//lua
local pos = Vector3.new(0, 0, 0)

I noticed that when constructing a Vector3 in Lua, it creates a C closure to build the Vector userdata. May I ask how I can avoid creating this closure? Because it impacts performance and additionally creates a GC object for the C closure.

ianfor avatar Apr 08 '25 11:04 ianfor