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

Expand on class conversion support #8

Open
JakobOvrum opened this issue Oct 2, 2010 · 10 comments
Open

Expand on class conversion support #8

JakobOvrum opened this issue Oct 2, 2010 · 10 comments
Assignees

Comments

@JakobOvrum
Copy link
Owner

Stuff that needs to be supported, if you happen to see this issue, please help me expand on this list.

  • Support all translatable operator overloads
  • Support entire overload sets, not just the first defined overload
  • Fix virtual function behaviour [done]
  • Support const and immutable class references
  • Properties and public data fields
  • Class registration with constructors and static members
@JesseKPhillips
Copy link
Contributor

Functions inside a class marked as const cause a compilation error.

I fixed this by adding cast(void*) on line 128 of conversions/functions.d

@JakobOvrum
Copy link
Owner Author

That just makes things worse. Const/immutable class references are not specially handled by the class converter. By casting away const like that you allow const references to be modified by calling non-const methods from Lua. This behaviour is, in some extreme cases, what you want, but the cast shouldn't be in LuaD, it should be done by the host application code.

A proper solution would be to handle const and immutable references by marking them as const or immutable respectively, and by overriding non-const and immutable methods (or only non-const methods when immutable) with an erroring stub function. This is a real issue though and it would be really cool for LuaD to properly handle it, I'll add it to the list.

@JesseKPhillips
Copy link
Contributor

I am not referring to the class reference. This is only a class functions that are const. While there could be an issue with it, I am not seeing one since Lua doesn't care about const and the method is still not going to modify any data when called from Lua (I don't know how you can make it do that).

Or maybe the code I modified effects more than just functions?

@Trass3r
Copy link

Trass3r commented Nov 17, 2010

Have there been problems with adding operator overloading etc or has it just not been done yet?

@JakobOvrum
Copy link
Owner Author

I think I have a couple of insignificant local commits towards it, there haven't been any problems. I just haven't been doing a lot of programming lately. I see that LuaD has garnered a bit of interest now, so it's definitively at the top of my list of things to work on.

I'll have a lot of time for programming in about three weeks.

Of course, it'd be awesome if someone would fork LuaD and help out, I'm still paying attention to github so I have time to address pull requests :)

@Trass3r
Copy link

Trass3r commented Nov 17, 2010

So push 'em ;)
I think I'll play around with it a bit.

@Trass3r
Copy link

Trass3r commented Nov 18, 2010

btw, the list is still missing property methods and public data fields ;)

@Trass3r
Copy link

Trass3r commented Nov 18, 2010

Oh, and of course real class registration is needed incl. constructors (I'm on it)
Could you elaborate on "Fix virtual function behaviour"?

EDIT: just so I don't forget it, what about functions with default argument values?

@JakobOvrum
Copy link
Owner Author

I expanded the list.

Default arguments are hard-coded at the call-site, so it would go under supporting overload sets - however, it's not that simple, since I don't think there's a way to check if a parameter has a default value with the current introspection facilities.

Virtual dispatch isn't working correctly right now because the method table is built directly from the first instance of a type pushed. The problem is that it's built directly, even for non-final methods. That means the same method will be used for all instances of that static type, even if they've actually overridden it.

I used to push a unique metatable for every class instance. This solves this particular problem, but introduces a whole bunch of others, and it's really slow compared to the current way.

The proper solution is to add a level of indirection for methods which can be virtual, so it would push a small wrapper method which took the address of the virtual method to be called before calling it, which would properly do the vtable lookup. The only problem is weaving this into the current method-pushing back-end cleanly - I haven't given it much time.

@JakobOvrum
Copy link
Owner Author

Virtual functions now work correctly. (6f7f2c3)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants