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

Possible to add a way to interface with uchar*? #44

Open
daurnimator opened this issue May 31, 2012 · 4 comments
Open

Possible to add a way to interface with uchar*? #44

daurnimator opened this issue May 31, 2012 · 4 comments

Comments

@daurnimator
Copy link

I'm working with a QImage and would appriciate a way to work with the raw uchar *
As a note: I am working in luajit, and using the ffi would be great!
If you could just give me a userdata (eg, img:bits() ) I can use ffi.cast

@mkottman
Copy link
Owner

Using FFI has been discussed with Mike Pall before, however there is no plan in supporting all the various intricacies of the C++ ABI between operating systems and compilers. Therefore LuaJIT-FFI-Qt is not to be expected soon.

You can try extending types.lua with definition for unsigned char * based on the available implementation of base_types['char const*'], and use lua_pushlightuserdata() instead.

@daurnimator
Copy link
Author

Thanks for hint; diff is below:

$ git diff -w
diff --git a/common/lqt_common.cpp b/common/lqt_common.cpp
index 56c7a7c..3924237 100644
--- a/common/lqt_common.cpp
+++ b/common/lqt_common.cpp
@@ -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;
diff --git a/common/lqt_common.hpp b/common/lqt_common.hpp
index de53760..690af14 100644
--- a/common/lqt_common.hpp
+++ b/common/lqt_common.hpp
@@ -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);
diff --git a/generator/types.lua b/generator/types.lua
index 8958fe2..d47aeb7 100644
--- a/generator/types.lua
+++ b/generator/types.lua
@@ -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,',
+}
 base_types['char'] = integer_type(3)
 base_types['unsigned char'] = integer_type(3)
 base_types['int'] = integer_type(1)

@daurnimator
Copy link
Author

Should I make a pull request?

@mkottman
Copy link
Owner

mkottman commented Jun 1, 2012

That would be great :)

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

No branches or pull requests

2 participants