Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Debug names of C functions for Luau #163

Closed
snaulX opened this issue Feb 25, 2024 · 8 comments · Fixed by #164
Closed

Debug names of C functions for Luau #163

snaulX opened this issue Feb 25, 2024 · 8 comments · Fixed by #164
Labels
enhancement New feature or request minor

Comments

@snaulX
Copy link

snaulX commented Feb 25, 2024

Luau when getting errors tries to find debug name of function, but as I see, LuaBridge in lua_pushcfunction_x and lua_pushcclosure_x set it empty. So I often get errors like invalid argument #1 to '' and it's hard to debug when your lua code has a lot of calls of C functions. Maybe you should make new lua_pushcfunction_x and lua_pushcclosure_x or modify existing to set this debug name properly. Also I'll try to implement it by myself in a PR, if you want.

@kunitoki
Copy link
Owner

kunitoki commented Feb 25, 2024

Makes sense, the purpose of these _x version of lua methods is to be able to make them usable by both puc lua, luajit and luau. If luau needs this debug name maybe we can make a macro instead ?

@snaulX
Copy link
Author

snaulX commented Feb 25, 2024

How it will looks like and will it be used in namespace/class bindings to set debug names for member/static functions?

@kunitoki
Copy link
Owner

kunitoki commented Feb 25, 2024

We could use the name provided in the addFunction to inject it into the method, will try something. Question, why luau is not able to determine the name of the lua function being called?

@kunitoki
Copy link
Owner

Can you write a repro case so we could add a unit test for it ?

@snaulX
Copy link
Author

snaulX commented Feb 25, 2024

There's no any special case for this. Just write binding for class and method, use it in Lua with wring argument and check for this error. Maybe debug name can be shown using some function but I didn't check.

class MyClass {
   void Foo(int a) {}
};

luabridge::getGlobalNamespace(L)
.beginClass<MyClass>("MyClass")
   .addMethod("Foo", &MyClass::Foo)
.endClass();
local myClass -- MyClass instance
myClass:Foo('wrong type of argument')

@kunitoki
Copy link
Owner

Could you check if #164 would work for you ?

@snaulX
Copy link
Author

snaulX commented Feb 26, 2024

For some reason, this branch won't working with my package manager - CPM.cmake.
luabridge_cpm
But you can check this out in these steps:

  • Make static int TestFunc(lua_State* L) { luaL_argerrorL(L, 1, "test message"); return 0; }
  • Add it to class bindings
  • Write lua code that uses this method
  • Check for the error invalid argument #1 to '' (test message)

Also you can use Visual Studio debugger and set breakpoint inside TestFunc and check call stack in Lua for function with your debug name. Luau's natvis must show it.

@kunitoki
Copy link
Owner

kunitoki commented Mar 2, 2024

As a side note, if you install a error handler callback when executing your lua code (from c++) incoking the binded method, you could print the traceback and the name of the function should appear.

@kunitoki kunitoki added enhancement New feature or request minor ready and removed ready labels Mar 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request minor
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants