2121 */
2222#include " LuaScriptMethod.hpp"
2323
24+ #include " ../LuaDebug.hpp"
2425#include " ../utils/stack_top_checker.hpp"
2526
2627namespace luagdextension {
2728
2829LuaScriptMethod::LuaScriptMethod (const StringName& name, sol::protected_function method)
2930 : name(name)
30- , method(method)
31+ , method(LuaObject::wrap_object<LuaFunction>( method) )
3132{
3233}
3334
3435bool LuaScriptMethod::is_valid () const {
35- return method.valid ();
36+ return method.is_valid ();
3637}
3738
3839int LuaScriptMethod::get_line_defined () const {
3940#ifdef DEBUG_ENABLED
40- lua_Debug lua_info;
41- method.push ();
42- lua_getinfo (method.lua_state (), " >S" , &lua_info);
43- return lua_info.linedefined ;
41+ return method->get_debug_info ()->get_line_defined ();
4442#else
4543 return -1 ;
4644#endif
4745}
4846
4947Variant LuaScriptMethod::get_argument_count () const {
5048#ifdef DEBUG_ENABLED
51- lua_Debug lua_info;
52- method.push ();
53- lua_getinfo (method.lua_state (), " >u" , &lua_info);
54- return lua_info.nparams ;
49+ return method->get_debug_info ()->get_nparams ();
5550#else
5651 return {};
5752#endif
@@ -62,22 +57,19 @@ MethodInfo LuaScriptMethod::to_method_info() const {
6257 mi.name = name;
6358
6459#ifdef DEBUG_ENABLED
65- sol::state_view state = method.lua_state ();
60+ sol::state_view state = method-> get_function () .lua_state ();
6661 StackTopChecker topcheck (state);
6762
68- lua_Debug lua_info;
69- method.push (state);
70- lua_getinfo (state, " >u" , &lua_info);
71-
72- auto methodpop = sol::stack::push_pop (state, method);
73- for (int i = 0 ; i < lua_info.nparams ; i++) {
63+ auto debug_info = method->get_debug_info ();
64+ auto methodpop = sol::stack::push_pop (state, method->get_function ());
65+ for (int i = 0 ; i < debug_info->get_nparams (); i++) {
7466 String arg_name = lua_getlocal (state, nullptr , i + 1 );
7567 if (i == 0 && arg_name == " self" ) {
7668 continue ;
7769 }
7870 mi.arguments .push_back (PropertyInfo (Variant::Type::NIL, arg_name));
7971 }
80- if (lua_info. isvararg ) {
72+ if (debug_info-> is_vararg () ) {
8173 mi.flags |= GDEXTENSION_METHOD_FLAG_VARARG;
8274 }
8375#endif
0 commit comments