Skip to content

Commit

Permalink
Primitives, SWIG rename fix
Browse files Browse the repository at this point in the history
NEW: primitives addon, not fully tested, so watch out and let me know =]

FIX: SWIG strip rename wasn't working when another "rename" appeared.
Fixed by renamimg to the final name directly
  • Loading branch information
gilzoide committed Nov 6, 2016
1 parent 2d77083 commit 3d44926
Show file tree
Hide file tree
Showing 13 changed files with 513 additions and 88 deletions.
11 changes: 5 additions & 6 deletions README.md
@@ -1,6 +1,6 @@
lallegro
========
Lua bindings for the [Allegro](http://liballeg.org/) game programming library
Lua bindings for the [Allegro 5.2](http://liballeg.org/) game programming library
using [SWIG](http://swig.org/).


Expand Down Expand Up @@ -29,10 +29,9 @@ al.destroy_display (disp)

Bindings
--------
1 to 1 function binding is provided to almost all the Allegro API. The
"Primitives" addon is the only one missing, for now. Functions are renamed so
the prefix `al_` is removed, so the calls to functions use the Lua module as
the Allegro namespace.
1 to 1 function binding is provided to almost all the Allegro API, including
addons. Functions are renamed so the prefix `al_` is removed, so the calls to
functions use the Lua module as the Allegro namespace.

Differences between the Allegro C API and this one is detailed in the
[API diff document](apidiff.md).
Expand Down Expand Up @@ -77,4 +76,4 @@ The [Allegro Documentation](http://liballeg.org/a5docs/trunk/index.html) should
be widly used, as _lallegro_ provides 1 to 1 bindings.

[LDoc](https://github.com/stevedonovan/LDoc) used for documenting the Lua
specific stuff. Generate with `ldoc .`.
specific stuff. Generate with `ldoc .`
7 changes: 7 additions & 0 deletions apidiff.md
@@ -1,6 +1,13 @@
C and Lua API differences
=========================

al\_init
--------
When exiting without calling `al_uninstall_system`, a segfault occurs when
initializing with the `al_init` macro. `lallegro.init` calls `al_install_system`
with a nil atexit\_ptr, to avoid this. The macro is still available as
`lallegro._init`

Platform Specific Functions
---------------------------
The platform specific functions require other headers, and other libraries to
Expand Down
4 changes: 2 additions & 2 deletions lallegro-scm-1.rockspec
Expand Up @@ -4,9 +4,9 @@ source = {
url = 'git://github.com/gilzoide/lallegro',
}
description = {
summary = 'Lua bindings for the Allegro 5 game programming library',
summary = 'Lua bindings for the Allegro 5.2 game programming library',
detailed = [[
Lua bindings for the Allegro 5 game programming library
Lua bindings for the Allegro 5.2 game programming library
]],
license = 'LGPLv3',
maintainer = 'gilzoide <gilzoide@gmail.com>'
Expand Down
4 changes: 3 additions & 1 deletion src/CMakeLists.txt
Expand Up @@ -27,6 +27,7 @@ swig_please_wrap_it (image)
swig_please_wrap_it (memfile)
swig_please_wrap_it (dialog)
swig_please_wrap_it (physfs)
swig_please_wrap_it (primitives)
swig_please_wrap_it (video)

# Copy Lua files
Expand All @@ -35,7 +36,8 @@ file (COPY ${luaSrc} DESTINATION ${CMAKE_PROJECT_NAME})

## Install ##
set (LUA_VER "${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}")
install (TARGETS core audio acodec color font ttf image memfile dialog physfs video
install (TARGETS core audio acodec color font ttf image memfile dialog physfs
primitives video
LIBRARY DESTINATION lib/lua/${LUA_VER}/${CMAKE_PROJECT_NAME})
install (FILES ${luaSrc}
DESTINATION share/lua/${LUA_VER}/${CMAKE_PROJECT_NAME})
2 changes: 1 addition & 1 deletion src/audio.i
Expand Up @@ -102,7 +102,7 @@ ALLEGRO_SAMPLE *al_create_sample(void *buf, unsigned int samples

void al_destroy_sample(ALLEGRO_SAMPLE *spl);

%apply ALLEGRO_SAMPLE_ID *OUTPUT { ALLEGRO_SAMPLE_ID *ret_id };
%rename al_play_sample _play_sample;
bool al_play_sample(ALLEGRO_SAMPLE *spl, float gain, float pan, float speed
, ALLEGRO_PLAYMODE loop, ALLEGRO_SAMPLE_ID *ret_id);

Expand Down
32 changes: 32 additions & 0 deletions src/common.i
Expand Up @@ -34,5 +34,37 @@
%apply unsigned int { uint32_t };
%apply long int { int64_t };

// C arrays (no pointers)
%typemap (in) float[ANY] (float temp[$1_dim0]) {
int i, size;
// assert length
lua_len (L, $input);
size = lua_tointeger (L, -1);
if (size != $1_dim0) {
luaL_error (L, "expected %d floats in table, not %d", $1_dim0, size);
}
for (i = 0; i < $1_dim0; i++) {
lua_geti (L, $input, i + 1);
temp[i] = luaL_checknumber (L, -1);
}
lua_pop (L, $1_dim0 + 1);
$1 = temp;
}
%typemap (in) int[ANY] (int temp[$1_dim0]) {
int i, size;
// assert length
lua_len (L, $input);
size = lua_tointeger (L, -1);
if (size != $1_dim0) {
luaL_error (L, "expected %d ints in table, not %d", $1_dim0, size);
}
for (i = 0; i < $1_dim0; i++) {
lua_geti (L, $input, i + 1);
temp[i] = luaL_checkinteger (L, -1);
}
lua_pop (L, $1_dim0 + 1);
$1 = temp;
}

// Strip the prepending "al_" from functions, so we use Lua's module as namespace
%rename ("%(strip:[al_])s") "";
35 changes: 18 additions & 17 deletions src/core.i
Expand Up @@ -30,7 +30,7 @@
%include <allegro5/base.h>

// Time: OUTPUT
%rename al_init_timeout al__init_timeout;
%rename al_init_timeout _init_timeout;
%include <allegro5/altime.h>
// Bitmap: OUTPUT
%apply int *OUTPUT { int *x, int *y, int *w, int *h };
Expand Down Expand Up @@ -76,18 +76,18 @@
%newobject al_get_current_directory;
%include <allegro5/fshook.h>
// Fullscreen modes: OUTPUT on Lua
%rename al_get_display_mode al__get_display_mode;
%rename al_get_display_mode _get_display_mode;
%include <allegro5/fullscreen_mode.h>
// Haptic: OUTPUT on Lua
%rename al_upload_haptic_effect al__upload_haptic_effect;
%rename al_upload_and_play_haptic_effect al__upload_and_play_haptic_effect;
%rename al_rumble_haptic al__rumble_haptic;
%rename al_upload_haptic_effect _upload_haptic_effect;
%rename al_upload_and_play_haptic_effect _upload_and_play_haptic_effect;
%rename al_rumble_haptic _rumble_haptic;
%include <allegro5/haptic.h>
// Joystick: OUTPUT on Lua
%rename al_get_joystick_state al__get_joystick_state;
%rename al_get_joystick_state _get_joystick_state;
%include <allegro5/joystick.h>
// Keyboard: OUTPUT on Lua
%rename al_get_keyboard_state al__get_keyboard_state;
%rename al_get_keyboard_state _get_keyboard_state;
%include <allegro5/keyboard.h>
/* Memory: macros
* I don't think Lua devs will be `malloc`ing stuff, but who knows
Expand All @@ -99,16 +99,16 @@
%ignore al_calloc;
%include <allegro5/memory.h>
// Monitor: OUTPUT on Lua
%rename al_get_monitor_info al__get_monitor_info;
%rename al_get_monitor_info _get_monitor_info;
%include <allegro5/monitor.h>
// Mouse: OUTPUT on Lua, OUTPUT
%rename al_get_mouse_state al__get_mouse_state;
%rename al_get_mouse_state _get_mouse_state;
%apply int *OUTPUT { int *ret_x, int *ret_y };
%include <allegro5/mouse.h>
//
%include <allegro5/mouse_cursor.h>
// Path: default argument
%rename al_path_cstr al__path_cstr;
%rename al_path_cstr _path_cstr;
%include <allegro5/path.h>
//
%include <allegro5/render_state.h>
Expand All @@ -128,16 +128,16 @@
%apply int *OUTPUT {
int *op, int *src, int *dst, int *alpha_op, int *alpha_src, int *alpha_dst
}
%rename al_store_state al__store_state;
%rename al_store_state _store_state;
%include <allegro5/tls.h>
// Touch Input: OUTPUT on Lua
%rename al_get_touch_input_state al__get_touch_input_state;
%rename al_get_touch_input_state _get_touch_input_state;
%include <allegro5/touch_input.h>
// Transformations: OUTPUT on Lua, INOUT
%rename al_copy_transform al__copy_transform;
%rename al_identity_transform al__identity_transform;
%rename al_build_transform al__build_transform;
%rename al_build_camera_transform al__build_camera_transform;
%rename al_copy_transform _copy_transform;
%rename al_identity_transform _identity_transform;
%rename al_build_transform _build_transform;
%rename al_build_camera_transform _build_camera_transform;
%apply float *INOUT { float *x, float *y, float *z };
%include <allegro5/transformations.h>
/* UTF-8: Lua 5.3 gives us basic UTF-8 encoding, and Allegro API doesn't really
Expand All @@ -155,5 +155,6 @@ int my_init (lua_State *L) {
%}

#ifdef ALLEGRO_UNSTABLE
%constant bool UNSTABLE = true;
#undef ALLEGRO_UNSTABLE
%constant bool ALLEGRO_UNSTABLE = true;
#endif
2 changes: 1 addition & 1 deletion src/dialog.i
Expand Up @@ -62,7 +62,7 @@ void al_close_native_text_log(ALLEGRO_TEXTLOG *textlog);
// This function originally have varargs, but SWIG doesn't like them much.
// Format your string before passing it here, and it's all ok. We assume it'll
// be called from the wrapper, with format as "%s", and the string
%rename al_append_native_text_log al__append_native_text_log;
%rename al_append_native_text_log _append_native_text_log;
void al_append_native_text_log(ALLEGRO_TEXTLOG *textlog, char const *format
, char const *text);

Expand Down
7 changes: 4 additions & 3 deletions src/font.i
Expand Up @@ -69,7 +69,7 @@ void al_get_text_dimensions(const ALLEGRO_FONT *f, char const *text,

uint32_t al_get_allegro_font_version(void);

%rename al_get_font_ranges al__get_font_ranges;
%rename al_get_font_ranges _get_font_ranges;
int al_get_font_ranges(ALLEGRO_FONT *f, int ranges_count, int *ranges);

void al_set_fallback_font(ALLEGRO_FONT *font, ALLEGRO_FONT *fallback);
Expand Down Expand Up @@ -97,8 +97,9 @@ void al_draw_multiline_text(const ALLEGRO_FONT *font, ALLEGRO_COLOR color

////////////////////////////////////////////////////////////////////////////////
// Bitmap fonts
%rename al_grab_font_from_bitmap al__grab_font_from_bitmap;
ALLEGRO_FONT *al_grab_font_from_bitmap(ALLEGRO_BITMAP *bmp, int ranges_n, const int ranges[]);
%rename al_grab_font_from_bitmap _grab_font_from_bitmap;
ALLEGRO_FONT *al_grab_font_from_bitmap(ALLEGRO_BITMAP *bmp, int ranges_n
, const int *ranges);

ALLEGRO_FONT *al_load_bitmap_font(const char *fname);

Expand Down

0 comments on commit 3d44926

Please sign in to comment.