Skip to content

Commit

Permalink
Move wesnoth.get_time_stamp and wesnoth.get_image_size to lua_kernel_…
Browse files Browse the repository at this point in the history
…base
  • Loading branch information
CelticMinstrel committed May 5, 2017
1 parent cce24bf commit 3bbb833
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 30 deletions.
31 changes: 1 addition & 30 deletions src/scripting/game_lua_kernel.cpp
Expand Up @@ -3300,34 +3300,7 @@ int game_lua_kernel::intf_redraw(lua_State *L)
screen.draw(true,true);
}
return 0;
}

/**
* Gets the dimension of an image.
* - Arg 1: string.
* - Ret 1: width.
* - Ret 2: height.
*/
static int intf_get_image_size(lua_State *L)
{
char const *m = luaL_checkstring(L, 1);
image::locator img(m);
if (!img.file_exists()) return 0;
surface s = get_image(img);
lua_pushinteger(L, s->w);
lua_pushinteger(L, s->h);
return 2;
}

/**
* Returns the time stamp, exactly as [set_variable] time=stamp does.
* - Ret 1: integer
*/
static int intf_get_time_stamp(lua_State *L)
{
lua_pushinteger(L, SDL_GetTicks());
return 1;
}
}}

/**
* Lua frontend to the modify_ai functionality
Expand Down Expand Up @@ -3957,8 +3930,6 @@ game_lua_kernel::game_lua_kernel(game_state & gs, play_controller & pc, reports
{ "debug_ai", &intf_debug_ai },
{ "eval_conditional", &intf_eval_conditional },
{ "get_era", &intf_get_era },
{ "get_image_size", &intf_get_image_size },
{ "get_time_stamp", &intf_get_time_stamp },
{ "get_traits", &intf_get_traits },
{ "get_viewing_side", &intf_get_viewing_side },
{ "modify_ai", &intf_modify_ai_old },
Expand Down
27 changes: 27 additions & 0 deletions src/scripting/lua_kernel_base.cpp
Expand Up @@ -276,6 +276,31 @@ int intf_log(lua_State *L) {
return 0;
}

/**
* Gets the dimension of an image.
* - Arg 1: string.
* - Ret 1: width.
* - Ret 2: height.
*/
static int intf_get_image_size(lua_State *L) {
char const *m = luaL_checkstring(L, 1);
image::locator img(m);
if(!img.file_exists()) return 0;
surface s = get_image(img);
lua_pushinteger(L, s->w);
lua_pushinteger(L, s->h);
return 2;
}

/**
* Returns the time stamp, exactly as [set_variable] time=stamp does.
* - Ret 1: integer
*/
static int intf_get_time_stamp(lua_State *L) {
lua_pushinteger(L, SDL_GetTicks());
return 1;


// End Callback implementations

// Template which allows to push member functions to the lua kernel base into lua as C functions, using a shim
Expand Down Expand Up @@ -401,6 +426,8 @@ lua_kernel_base::lua_kernel_base()
{ "random", &intf_random },
{ "wml_matches_filter", &intf_wml_matches_filter },
{ "log", &intf_log },
{ "get_image_size", &intf_get_image_size },
{ "get_time_stamp", &intf_get_time_stamp },
{ nullptr, nullptr }
};

Expand Down

0 comments on commit 3bbb833

Please sign in to comment.