Skip to content
Permalink
Browse files

Replace macros for lua binding

  • Loading branch information...
TheCycoONE committed Apr 17, 2019
1 parent 4f70107 commit e4aa015b826dfc4ac635fa5bf5263e7dd51cdcf7
@@ -271,9 +271,9 @@ int luaopen_th(lua_State *L)

// Misc. functions
lua_settop(L, oState.top);
luaT_setfunction(l_load_strings, "LoadStrings");
luaT_setfunction(l_get_compile_options, "GetCompileOptions");
luaT_setfunction(bootstrap_lua_resources, "GetBuiltinFont");
add_lua_function(pState, l_load_strings, "LoadStrings");
add_lua_function(pState, l_get_compile_options, "GetCompileOptions");
add_lua_function(pState, bootstrap_lua_resources, "GetBuiltinFont");

// Classes
lua_register_map(pState);
@@ -652,21 +652,22 @@ int l_srl_is_dead(lua_State *L)
void lua_register_anims(const lua_register_state *pState)
{
// Anims
luaT_class(animation_manager, l_anims_new, "anims", lua_metatable::anims);
luaT_setfunction(l_anims_load, "load");
luaT_setfunction(l_anims_loadcustom, "loadCustom");
luaT_setfunction(l_anims_set_spritesheet, "setSheet", lua_metatable::sheet);
luaT_setfunction(l_anims_set_canvas, "setCanvas", lua_metatable::surface);
luaT_setfunction(l_anims_getanims, "getAnimations");
luaT_setfunction(l_anims_getfirst, "getFirstFrame");
luaT_setfunction(l_anims_getnext, "getNextFrame");
luaT_setfunction(l_anims_set_alt_pal, "setAnimationGhostPalette");
luaT_setfunction(l_anims_set_marker, "setFrameMarker");
luaT_setfunction(l_anims_set_secondary_marker, "setFrameSecondaryMarker");
luaT_setfunction(l_anims_draw, "draw", lua_metatable::surface, lua_metatable::layers);
luaT_setconstant("Alt32_GreyScale", thdf_alt32_grey_scale);
luaT_setconstant("Alt32_BlueRedSwap", thdf_alt32_blue_red_swap);
luaT_endclass();
{
lua_class_binding<animation_manager> lcb(pState, "anims", l_anims_new, lua_metatable::anims);
lcb.add_function(l_anims_load, "load");
lcb.add_function(l_anims_loadcustom, "loadCustom");
lcb.add_function(l_anims_set_spritesheet, "setSheet", lua_metatable::sheet);
lcb.add_function(l_anims_set_canvas, "setCanvas", lua_metatable::surface);
lcb.add_function(l_anims_getanims, "getAnimations");
lcb.add_function(l_anims_getfirst, "getFirstFrame");
lcb.add_function(l_anims_getnext, "getNextFrame");
lcb.add_function(l_anims_set_alt_pal, "setAnimationGhostPalette");
lcb.add_function(l_anims_set_marker, "setFrameMarker");
lcb.add_function(l_anims_set_secondary_marker, "setFrameSecondaryMarker");
lcb.add_function(l_anims_draw, "draw", lua_metatable::surface, lua_metatable::layers);
lcb.add_constant("Alt32_GreyScale", thdf_alt32_grey_scale);
lcb.add_constant("Alt32_BlueRedSwap", thdf_alt32_blue_red_swap);
}

// Weak table at AnimMetatable[1] for light UD -> object lookup
// For hitTest / setHitTestResult
@@ -687,39 +688,40 @@ void lua_register_anims(const lua_register_state *pState)
lua_rawseti(pState->L, pState->metatables[static_cast<size_t>(lua_metatable::anim)], 2);

// Anim
luaT_class(animation, l_anim_new<animation>, "animation", lua_metatable::anim);
luaT_setmetamethod(l_anim_persist<animation>, "persist");
luaT_setmetamethod(l_anim_pre_depersist<animation>, "pre_depersist");
luaT_setmetamethod(l_anim_depersist<animation>, "depersist");
luaT_setfunction(l_anim_set_anim, "setAnimation", lua_metatable::anims);
luaT_setfunction(l_anim_set_crop, "setCrop");
luaT_setfunction(l_anim_get_crop, "getCrop");
luaT_setfunction(l_anim_set_morph, "setMorph");
luaT_setfunction(l_anim_set_frame, "setFrame");
luaT_setfunction(l_anim_get_frame, "getFrame");
luaT_setfunction(l_anim_get_anim, "getAnimation");
luaT_setfunction(l_anim_set_tile<animation>, "setTile", lua_metatable::map);
luaT_setfunction(l_anim_get_tile, "getTile");
luaT_setfunction(l_anim_set_parent, "setParent");
luaT_setfunction(l_anim_set_flag<animation>, "setFlag");
luaT_setfunction(l_anim_set_flag_partial<animation>, "setPartialFlag");
luaT_setfunction(l_anim_get_flag<animation>, "getFlag");
luaT_setfunction(l_anim_make_visible<animation>, "makeVisible");
luaT_setfunction(l_anim_make_invisible<animation>, "makeInvisible");
luaT_setfunction(l_anim_set_tag, "setTag");
luaT_setfunction(l_anim_get_tag, "getTag");
luaT_setfunction(l_anim_set_position<animation>, "setPosition");
luaT_setfunction(l_anim_get_position, "getPosition");
luaT_setfunction(l_anim_set_speed<animation>, "setSpeed");
luaT_setfunction(l_anim_set_layer<animation>, "setLayer");
luaT_setfunction(l_anim_set_layers_from, "setLayersFrom");
luaT_setfunction(l_anim_set_hitresult, "setHitTestResult");
luaT_setfunction(l_anim_get_marker, "getMarker");
luaT_setfunction(l_anim_get_secondary_marker, "getSecondaryMarker");
luaT_setfunction(l_anim_tick<animation>, "tick");
luaT_setfunction(l_anim_draw<animation>, "draw", lua_metatable::surface);
luaT_setfunction(l_anim_set_drawable_layer, "setDrawingLayer");
luaT_endclass();
{
lua_class_binding<animation> lcb(pState, "animation", l_anim_new<animation>, lua_metatable::anim);
lcb.add_metamethod(l_anim_persist<animation>, "persist");
lcb.add_metamethod(l_anim_pre_depersist<animation>, "pre_depersist");
lcb.add_metamethod(l_anim_depersist<animation>, "depersist");
lcb.add_function(l_anim_set_anim, "setAnimation", lua_metatable::anims);
lcb.add_function(l_anim_set_crop, "setCrop");
lcb.add_function(l_anim_get_crop, "getCrop");
lcb.add_function(l_anim_set_morph, "setMorph");
lcb.add_function(l_anim_set_frame, "setFrame");
lcb.add_function(l_anim_get_frame, "getFrame");
lcb.add_function(l_anim_get_anim, "getAnimation");
lcb.add_function(l_anim_set_tile<animation>, "setTile", lua_metatable::map);
lcb.add_function(l_anim_get_tile, "getTile");
lcb.add_function(l_anim_set_parent, "setParent");
lcb.add_function(l_anim_set_flag<animation>, "setFlag");
lcb.add_function(l_anim_set_flag_partial<animation>, "setPartialFlag");
lcb.add_function(l_anim_get_flag<animation>, "getFlag");
lcb.add_function(l_anim_make_visible<animation>, "makeVisible");
lcb.add_function(l_anim_make_invisible<animation>, "makeInvisible");
lcb.add_function(l_anim_set_tag, "setTag");
lcb.add_function(l_anim_get_tag, "getTag");
lcb.add_function(l_anim_set_position<animation>, "setPosition");
lcb.add_function(l_anim_get_position, "getPosition");
lcb.add_function(l_anim_set_speed<animation>, "setSpeed");
lcb.add_function(l_anim_set_layer<animation>, "setLayer");
lcb.add_function(l_anim_set_layers_from, "setLayersFrom");
lcb.add_function(l_anim_set_hitresult, "setHitTestResult");
lcb.add_function(l_anim_get_marker, "getMarker");
lcb.add_function(l_anim_get_secondary_marker, "getSecondaryMarker");
lcb.add_function(l_anim_tick<animation>, "tick");
lcb.add_function(l_anim_draw<animation>, "draw", lua_metatable::surface);
lcb.add_function(l_anim_set_drawable_layer, "setDrawingLayer");
}

// Duplicate AnimMetatable[1,2] to SpriteListMetatable[1,2]
lua_rawgeti(pState->L, pState->metatables[static_cast<size_t>(lua_metatable::anim)], 1);
@@ -728,24 +730,25 @@ void lua_register_anims(const lua_register_state *pState)
lua_rawseti(pState->L, pState->metatables[static_cast<size_t>(lua_metatable::sprite_list)], 2);

// SpriteList
luaT_class(sprite_render_list, l_anim_new<sprite_render_list>, "spriteList", lua_metatable::sprite_list);
luaT_setmetamethod(l_anim_persist<sprite_render_list>, "persist");
luaT_setmetamethod(l_anim_pre_depersist<sprite_render_list>, "pre_depersist");
luaT_setmetamethod(l_anim_depersist<sprite_render_list>, "depersist");
luaT_setfunction(l_srl_set_sheet, "setSheet", lua_metatable::sheet);
luaT_setfunction(l_srl_append, "append");
luaT_setfunction(l_srl_set_lifetime, "setLifetime");
luaT_setfunction(l_srl_is_dead, "isDead");
luaT_setfunction(l_anim_set_tile<sprite_render_list>, "setTile", lua_metatable::map);
luaT_setfunction(l_anim_set_flag<sprite_render_list>, "setFlag");
luaT_setfunction(l_anim_set_flag_partial<sprite_render_list>, "setPartialFlag");
luaT_setfunction(l_anim_get_flag<sprite_render_list>, "getFlag");
luaT_setfunction(l_anim_make_visible<sprite_render_list>, "makeVisible");
luaT_setfunction(l_anim_make_invisible<sprite_render_list>, "makeInvisible");
luaT_setfunction(l_anim_set_position<sprite_render_list>, "setPosition");
luaT_setfunction(l_anim_set_speed<sprite_render_list>, "setSpeed");
luaT_setfunction(l_anim_set_layer<sprite_render_list>, "setLayer");
luaT_setfunction(l_anim_tick<sprite_render_list>, "tick");
luaT_setfunction(l_anim_draw<sprite_render_list>, "draw", lua_metatable::surface);
luaT_endclass();
{
lua_class_binding<sprite_render_list> lcb(pState, "spriteList", l_anim_new<sprite_render_list>, lua_metatable::sprite_list);
lcb.add_metamethod(l_anim_persist<sprite_render_list>, "persist");
lcb.add_metamethod(l_anim_pre_depersist<sprite_render_list>, "pre_depersist");
lcb.add_metamethod(l_anim_depersist<sprite_render_list>, "depersist");
lcb.add_function(l_srl_set_sheet, "setSheet", lua_metatable::sheet);
lcb.add_function(l_srl_append, "append");
lcb.add_function(l_srl_set_lifetime, "setLifetime");
lcb.add_function(l_srl_is_dead, "isDead");
lcb.add_function(l_anim_set_tile<sprite_render_list>, "setTile", lua_metatable::map);
lcb.add_function(l_anim_set_flag<sprite_render_list>, "setFlag");
lcb.add_function(l_anim_set_flag_partial<sprite_render_list>, "setPartialFlag");
lcb.add_function(l_anim_get_flag<sprite_render_list>, "getFlag");
lcb.add_function(l_anim_make_visible<sprite_render_list>, "makeVisible");
lcb.add_function(l_anim_make_invisible<sprite_render_list>, "makeInvisible");
lcb.add_function(l_anim_set_position<sprite_render_list>, "setPosition");
lcb.add_function(l_anim_set_speed<sprite_render_list>, "setSpeed");
lcb.add_function(l_anim_set_layer<sprite_render_list>, "setLayer");
lcb.add_function(l_anim_tick<sprite_render_list>, "tick");
lcb.add_function(l_anim_draw<sprite_render_list>, "draw", lua_metatable::surface);
}
}
@@ -878,100 +878,110 @@ int l_line_depersist(lua_State *L)
void lua_register_gfx(const lua_register_state *pState)
{
// Palette
luaT_class(palette, l_palette_new, "palette", lua_metatable::palette);
luaT_setfunction(l_palette_load, "load");
luaT_setfunction(l_palette_set_entry, "setEntry");
luaT_endclass();
{
lua_class_binding<palette> lcb(pState, "palette", l_palette_new, lua_metatable::palette);
lcb.add_function(l_palette_load, "load");
lcb.add_function(l_palette_set_entry, "setEntry");
}

// Raw bitmap
luaT_class(raw_bitmap, l_rawbitmap_new, "bitmap", lua_metatable::bitmap);
luaT_setfunction(l_rawbitmap_load, "load", lua_metatable::surface);
luaT_setfunction(l_rawbitmap_set_pal, "setPalette", lua_metatable::palette);
luaT_setfunction(l_rawbitmap_draw, "draw", lua_metatable::surface);
luaT_endclass();
{
lua_class_binding<raw_bitmap> lcb(pState, "bitmap", l_rawbitmap_new, lua_metatable::bitmap);
lcb.add_function(l_rawbitmap_load, "load", lua_metatable::surface);
lcb.add_function(l_rawbitmap_set_pal, "setPalette", lua_metatable::palette);
lcb.add_function(l_rawbitmap_draw, "draw", lua_metatable::surface);
}

// Sprite sheet
luaT_class(sprite_sheet, l_spritesheet_new, "sheet", lua_metatable::sheet);
luaT_setmetamethod(l_spritesheet_count, "len");
luaT_setfunction(l_spritesheet_load, "load", lua_metatable::surface);
luaT_setfunction(l_spritesheet_set_pal, "setPalette", lua_metatable::palette);
luaT_setfunction(l_spritesheet_size, "size");
luaT_setfunction(l_spritesheet_draw, "draw", lua_metatable::surface);
luaT_setfunction(l_spritesheet_hittest, "hitTest");
luaT_setfunction(l_spritesheet_isvisible, "isVisible");
luaT_endclass();
{
lua_class_binding<sprite_sheet> lcb(pState, "sheet", l_spritesheet_new, lua_metatable::sheet);
lcb.add_metamethod(l_spritesheet_count, "len");
lcb.add_function(l_spritesheet_load, "load", lua_metatable::surface);
lcb.add_function(l_spritesheet_set_pal, "setPalette", lua_metatable::palette);
lcb.add_function(l_spritesheet_size, "size");
lcb.add_function(l_spritesheet_draw, "draw", lua_metatable::surface);
lcb.add_function(l_spritesheet_hittest, "hitTest");
lcb.add_function(l_spritesheet_isvisible, "isVisible");
}

// Font
// Also adapt the font proxy meta table (font_proxy_mt) in graphics.lua.
luaT_class(font, l_font_new, "font", lua_metatable::font);
luaT_setfunction(l_font_get_size, "sizeOf");
luaT_setfunction(l_font_draw, "draw", lua_metatable::surface);
luaT_setfunction(l_font_draw_wrapped, "drawWrapped", lua_metatable::surface);
luaT_setfunction(l_font_draw_tooltip, "drawTooltip", lua_metatable::surface);
luaT_endclass();
{
lua_class_binding<font> lcb(pState, "font", l_font_new, lua_metatable::font);
lcb.add_function(l_font_get_size, "sizeOf");
lcb.add_function(l_font_draw, "draw", lua_metatable::surface);
lcb.add_function(l_font_draw_wrapped, "drawWrapped", lua_metatable::surface);
lcb.add_function(l_font_draw_tooltip, "drawTooltip", lua_metatable::surface);
}

// BitmapFont
luaT_class(bitmap_font, l_bitmap_font_new, "bitmap_font", lua_metatable::bitmap_font);
luaT_superclass(lua_metatable::font);
luaT_setfunction(l_bitmap_font_set_spritesheet, "setSheet", lua_metatable::sheet);
luaT_setfunction(l_bitmap_font_get_spritesheet, "getSheet", lua_metatable::sheet);
luaT_setfunction(l_bitmap_font_set_sep, "setSeparation");
luaT_endclass();
{
lua_class_binding<bitmap_font> lcb(pState, "bitmap_font", l_bitmap_font_new, lua_metatable::bitmap_font);
lcb.set_superclass(lua_metatable::font);
lcb.add_function(l_bitmap_font_set_spritesheet, "setSheet", lua_metatable::sheet);
lcb.add_function(l_bitmap_font_get_spritesheet, "getSheet", lua_metatable::sheet);
lcb.add_function(l_bitmap_font_set_sep, "setSeparation");
}

#ifdef CORSIX_TH_USE_FREETYPE2
// FreeTypeFont
luaT_class(freetype_font, l_freetype_font_new, "freetype_font", lua_metatable::freetype_font);
luaT_superclass(lua_metatable::font);
luaT_setfunction(l_freetype_font_set_spritesheet, "setSheet", lua_metatable::sheet);
luaT_setfunction(l_freetype_font_set_face, "setFace");
luaT_setfunction(l_freetype_font_get_copyright, "getCopyrightNotice");
luaT_setfunction(l_freetype_font_clear_cache, "clearCache");
luaT_endclass();
{
lua_class_binding<freetype_font> lcb(pState, "freetype_font", l_freetype_font_new, lua_metatable::freetype_font);
lcb.set_superclass(lua_metatable::font);
lcb.add_function(l_freetype_font_set_spritesheet, "setSheet", lua_metatable::sheet);
lcb.add_function(l_freetype_font_set_face, "setFace");
lcb.add_function(l_freetype_font_get_copyright, "getCopyrightNotice");
lcb.add_function(l_freetype_font_clear_cache, "clearCache");
}
#endif

// Layers
luaT_class(layers, l_layers_new, "layers", lua_metatable::layers);
luaT_setmetamethod(l_layers_get, "index");
luaT_setmetamethod(l_layers_set, "newindex");
luaT_setmetamethod(l_layers_persist, "persist");
luaT_setmetamethod(l_layers_depersist, "depersist");
luaT_endclass();
{
lua_class_binding<layers> lcb(pState, "layers", l_layers_new, lua_metatable::layers);
lcb.add_metamethod(l_layers_get, "index");
lcb.add_metamethod(l_layers_set, "newindex");
lcb.add_metamethod(l_layers_persist, "persist");
lcb.add_metamethod(l_layers_depersist, "depersist");
}

// Cursor
luaT_class(cursor, l_cursor_new, "cursor", lua_metatable::cursor);
luaT_setfunction(l_cursor_load, "load", lua_metatable::sheet);
luaT_setfunction(l_cursor_use, "use", lua_metatable::surface);
luaT_setfunction(l_cursor_position, "setPosition", lua_metatable::surface);
luaT_endclass();
{
lua_class_binding<cursor> lcb(pState, "cursor", l_cursor_new, lua_metatable::cursor);
lcb.add_function(l_cursor_load, "load", lua_metatable::sheet);
lcb.add_function(l_cursor_use, "use", lua_metatable::surface);
lcb.add_function(l_cursor_position, "setPosition", lua_metatable::surface);
}

// Surface
luaT_class(render_target, l_surface_new, "surface", lua_metatable::surface);
luaT_setfunction(l_surface_update, "update");
luaT_setfunction(l_surface_destroy, "destroy");
luaT_setfunction(l_surface_fill_black, "fillBlack");
luaT_setfunction(l_surface_start_frame, "startFrame");
luaT_setfunction(l_surface_end_frame, "endFrame");
luaT_setfunction(l_surface_nonoverlapping, "nonOverlapping");
luaT_setfunction(l_surface_map, "mapRGB");
luaT_setfunction(l_surface_set_blue_filter_active, "setBlueFilterActive");
luaT_setfunction(l_surface_rect, "drawRect");
luaT_setfunction(l_surface_get_clip, "getClip");
luaT_setfunction(l_surface_set_clip, "setClip");
luaT_setfunction(l_surface_screenshot, "takeScreenshot");
luaT_setfunction(l_surface_scale, "scale");
luaT_setfunction(l_surface_set_caption, "setCaption");
luaT_setfunction(l_surface_get_renderer_details, "getRendererDetails");
luaT_setfunction(l_surface_set_capture_mouse, "setCaptureMouse");
luaT_endclass();
{
lua_class_binding<render_target> lcb(pState, "surface", l_surface_new, lua_metatable::surface);
lcb.add_function(l_surface_update, "update");
lcb.add_function(l_surface_destroy, "destroy");
lcb.add_function(l_surface_fill_black, "fillBlack");
lcb.add_function(l_surface_start_frame, "startFrame");
lcb.add_function(l_surface_end_frame, "endFrame");
lcb.add_function(l_surface_nonoverlapping, "nonOverlapping");
lcb.add_function(l_surface_map, "mapRGB");
lcb.add_function(l_surface_set_blue_filter_active, "setBlueFilterActive");
lcb.add_function(l_surface_rect, "drawRect");
lcb.add_function(l_surface_get_clip, "getClip");
lcb.add_function(l_surface_set_clip, "setClip");
lcb.add_function(l_surface_screenshot, "takeScreenshot");
lcb.add_function(l_surface_scale, "scale");
lcb.add_function(l_surface_set_caption, "setCaption");
lcb.add_function(l_surface_get_renderer_details, "getRendererDetails");
lcb.add_function(l_surface_set_capture_mouse, "setCaptureMouse");
}

// Line
luaT_class(line, l_line_new, "line", lua_metatable::line);
luaT_setfunction(l_move_to, "moveTo");
luaT_setfunction(l_line_to, "lineTo");
luaT_setfunction(l_set_width, "setWidth");
luaT_setfunction(l_set_colour, "setColour");
luaT_setfunction(l_line_draw, "draw", lua_metatable::surface);
luaT_setmetamethod(l_line_persist, "persist");
luaT_setmetamethod(l_line_depersist, "depersist");
luaT_endclass();
{
lua_class_binding<line> lcb(pState, "line", l_line_new, lua_metatable::line);
lcb.add_function(l_move_to, "moveTo");
lcb.add_function(l_line_to, "lineTo");
lcb.add_function(l_set_width, "setWidth");
lcb.add_function(l_set_colour, "setColour");
lcb.add_function(l_line_draw, "draw", lua_metatable::surface);
lcb.add_metamethod(l_line_persist, "persist");
lcb.add_metamethod(l_line_depersist, "depersist");
}
}

0 comments on commit e4aa015

Please sign in to comment.
You can’t perform that action at this time.