Java and SDL_GetKeyState ()

I am trying to convert to Java some code that uses SDL. I am using sdljava bindings.

sdljava uses SWIG as a bridge between the C data types of C and Java. To get the equivalent SDL_GetKeyState(), sdljava provides a method SWIG_SDLEvent.SDL_GetKeyState()that returns something called SWIGTYPE_p_unsigned_char.

Of course, Java does not have a type unsigned char, and I do not know that the compiler believes that this type of SWIG is actually Java. Normal use SDL_GetKeyState()in C / C ++ would be something like:

Uint8 *ks = SDL_GetKeyState(NULL);
if ( ks[SDLK_UP] ) { /* handle Up key */ }

... where are the SDL caching values, such as the SDLK_UP index, into the array.

However, the following Java code:

SWIGTYPE_p_unsigned_char ks = SWIG_SDLEvent.SDL_GetKeyState(null);
if ( ks[SDLKeyValues.SDLK_UP] != 0) { /* handle Up key */ }

results in a compiler error: "The type of the expression must be an array type, but it is allowed for SWIGTYPE_p_unsigned_char."

, SWIG_SDLEvent.SDL_GetKeyState(), , , ?

+1
2

, SWIG Java, :

SWIGTYPE_p_unsigned_char , , " " Java.

, Java - http://www.swig.org/Doc1.3/Java.html , Java

%inline %{
 Uint8 getValueFromArray(Uint8* array, size_t i) {
  return array[i];
 }
%}
0

, , . , carrays.i arrays_java.i , ; SWIG, Java , , SDL_GetKeyState(), Java.

SWIG , FillMeInAsSizeCannotBeDeterminedAutomatically, . , , , SDL_GetKeyState(), , . , Java SWIG, .

+1

Source: https://habr.com/ru/post/1719453/


All Articles