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

unsigned char* support via lightuserdata #46

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions common/lqt_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,9 @@ bool lqtL_isstring (lua_State *L, int i) {
bool lqtL_isboolean (lua_State *L, int i) {
return lua_type(L, i)==LUA_TBOOLEAN;
}
bool lqtL_islightuserdata (lua_State *L, int i) {
return lua_type(L, i)==LUA_TLIGHTUSERDATA;
}
bool lqtL_missarg (lua_State *L, int index, int n) {
bool ret = true;
int i = 0;
Expand Down
1 change: 1 addition & 0 deletions common/lqt_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ bool lqtL_isinteger (lua_State *, int);
bool lqtL_isnumber (lua_State *, int);
bool lqtL_isstring (lua_State *, int);
bool lqtL_isboolean (lua_State *, int);
bool lqtL_islightuserdata (lua_State *, int);

bool lqtL_missarg (lua_State *, int, int);
//int lqtL_baseindex (lua_State *, int, int);
Expand Down
12 changes: 12 additions & 0 deletions generator/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ base_types['char const*'] = {
end,
onstack = 'string,',
}
base_types['unsigned char*'] = {
get = function(j)
return '(unsigned char*)lua_touserdata(L, '..tostring(j)..')', 1
end,
push = function(j) -- must handle arguments (e.g. in virtual callbacks) and return values
return 'lua_pushlightuserdata(L, '..tostring(j)..')', 1
end,
test = function(j)
return 'lqtL_islightuserdata(L, '..tostring(j)..')', 1
end,
onstack = 'string,',
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure of this line.... I just copied it from above.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a check of what Lua stack should look like in order to correctly convert the type from Lua -> C++. Since we are dealing with userdata, I think it should state 'userdata'.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is it passed to/from? just the lua side type()?
For other purposes it might need to be lightuserdata....

Note: I have tested this (using QImage::bits) and everything seemed to work.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, by looking at the code, it only seems to be used to distinguish overloaded methods, so it should be relatively harmless...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, what is it compared to?
I note that integer_type has integer; so it's probably not the lua type function....

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is used to construct a "signature" of a method. It is generated in generator/classes.lua in function fill_wrapper_code, and subsequently used in print_metatable. The main idea was to use only a single overloaded function where there are multiple C++ versions that do not make sense in Lua. As an example - fun(char), fun(int) and fun(long) would all generate "integer" signatures, but the long version would get the least "defect" and therefore be chosen, the others will not be generated.

It is not actually used in any checking during runtime (there is another mechanism for that).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok then; should I make it userdata or lightuserdata?

}
base_types['char'] = integer_type(3)
base_types['unsigned char'] = integer_type(3)
base_types['int'] = integer_type(1)
Expand Down