refactor: complete 'lua' namespace use
This commit is contained in:
parent
90bc86408b
commit
913e5983b1
@ -24,6 +24,6 @@ extern const luaL_Reg tomllib [];
|
||||
extern const luaL_Reg worldlib [];
|
||||
|
||||
// Lua Overrides
|
||||
extern int l_print(lua_State* L);
|
||||
extern int l_print(lua::State* L);
|
||||
|
||||
#endif // LOGIC_SCRIPTING_API_LUA_HPP_
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
|
||||
inline const char* DEFAULT_CHANNEL = "regular";
|
||||
|
||||
inline int extract_channel_index(lua_State* L, int idx) {
|
||||
inline int extract_channel_index(lua::State* L, int idx) {
|
||||
const char* channel = DEFAULT_CHANNEL;
|
||||
if (!lua::isnoneornil(L, idx)) {
|
||||
channel = lua::tostring(L, idx);
|
||||
@ -20,11 +20,11 @@ inline int extract_channel_index(lua_State* L, int idx) {
|
||||
inline audio::speakerid_t play_sound(
|
||||
const char* name,
|
||||
bool relative,
|
||||
lua_Number x,
|
||||
lua_Number y,
|
||||
lua_Number z,
|
||||
lua_Number volume,
|
||||
lua_Number pitch,
|
||||
lua::Number x,
|
||||
lua::Number y,
|
||||
lua::Number z,
|
||||
lua::Number volume,
|
||||
lua::Number pitch,
|
||||
bool loop,
|
||||
int channel
|
||||
) {
|
||||
@ -55,11 +55,11 @@ inline audio::speakerid_t play_sound(
|
||||
inline audio::speakerid_t play_stream(
|
||||
const char* filename,
|
||||
bool relative,
|
||||
lua_Number x,
|
||||
lua_Number y,
|
||||
lua_Number z,
|
||||
lua_Number volume,
|
||||
lua_Number pitch,
|
||||
lua::Number x,
|
||||
lua::Number y,
|
||||
lua::Number z,
|
||||
lua::Number volume,
|
||||
lua::Number pitch,
|
||||
bool loop,
|
||||
int channel
|
||||
) {
|
||||
@ -91,8 +91,8 @@ inline audio::speakerid_t play_stream(
|
||||
/// pitch: number,
|
||||
/// channel: string = "regular",
|
||||
/// loop: bool = false)
|
||||
static int l_audio_play_stream(lua_State* L) {
|
||||
return lua::pushinteger(L, static_cast<lua_Integer>(
|
||||
static int l_audio_play_stream(lua::State* L) {
|
||||
return lua::pushinteger(L, static_cast<lua::Integer>(
|
||||
play_stream(
|
||||
lua::tostring(L, 1),
|
||||
false,
|
||||
@ -113,8 +113,8 @@ static int l_audio_play_stream(lua_State* L) {
|
||||
/// pitch: number,
|
||||
/// channel: string = "regular",
|
||||
/// loop: bool = false)
|
||||
static int l_audio_play_stream_2d(lua_State* L) {
|
||||
return lua::pushinteger(L, static_cast<lua_Integer>(
|
||||
static int l_audio_play_stream_2d(lua::State* L) {
|
||||
return lua::pushinteger(L, static_cast<lua::Integer>(
|
||||
play_stream(
|
||||
lua::tostring(L, 1),
|
||||
true,
|
||||
@ -136,8 +136,8 @@ static int l_audio_play_stream_2d(lua_State* L) {
|
||||
/// pitch: number,
|
||||
/// channel: string = "regular",
|
||||
/// loop: bool = false)
|
||||
static int l_audio_play_sound(lua_State* L) {
|
||||
return lua::pushinteger(L, static_cast<lua_Integer>(
|
||||
static int l_audio_play_sound(lua::State* L) {
|
||||
return lua::pushinteger(L, static_cast<lua::Integer>(
|
||||
play_sound(
|
||||
lua::tostring(L, 1),
|
||||
false,
|
||||
@ -158,8 +158,8 @@ static int l_audio_play_sound(lua_State* L) {
|
||||
/// pitch: number,
|
||||
/// channel: string = "regular",
|
||||
/// loop: bool = false)
|
||||
static int l_audio_play_sound_2d(lua_State* L) {
|
||||
return lua::pushinteger(L, static_cast<lua_Integer>(
|
||||
static int l_audio_play_sound_2d(lua::State* L) {
|
||||
return lua::pushinteger(L, static_cast<lua::Integer>(
|
||||
play_sound(
|
||||
lua::tostring(L, 1),
|
||||
true,
|
||||
@ -173,7 +173,7 @@ static int l_audio_play_sound_2d(lua_State* L) {
|
||||
}
|
||||
|
||||
/// @brief audio.stop(speakerid: integer) -> nil
|
||||
static int l_audio_stop(lua_State* L) {
|
||||
static int l_audio_stop(lua::State* L) {
|
||||
auto speaker = audio::get_speaker(lua::tointeger(L, 1));
|
||||
if (speaker != nullptr) {
|
||||
speaker->stop();
|
||||
@ -182,7 +182,7 @@ static int l_audio_stop(lua_State* L) {
|
||||
}
|
||||
|
||||
/// @brief audio.pause(speakerid: integer) -> nil
|
||||
static int l_audio_pause(lua_State* L) {
|
||||
static int l_audio_pause(lua::State* L) {
|
||||
auto speaker = audio::get_speaker(lua::tointeger(L, 1));
|
||||
if (speaker != nullptr) {
|
||||
speaker->pause();
|
||||
@ -191,7 +191,7 @@ static int l_audio_pause(lua_State* L) {
|
||||
}
|
||||
|
||||
/// @brief audio.resume(speakerid: integer) -> nil
|
||||
static int l_audio_resume(lua_State* L) {
|
||||
static int l_audio_resume(lua::State* L) {
|
||||
auto speaker = audio::get_speaker(lua::tointeger(L, 1));
|
||||
if (speaker != nullptr && speaker->isPaused()) {
|
||||
speaker->play();
|
||||
@ -200,7 +200,7 @@ static int l_audio_resume(lua_State* L) {
|
||||
}
|
||||
|
||||
/// @brief audio.set_loop(speakerid: integer, value: bool) -> nil
|
||||
static int l_audio_set_loop(lua_State* L) {
|
||||
static int l_audio_set_loop(lua::State* L) {
|
||||
auto speaker = audio::get_speaker(lua::tointeger(L, 1));
|
||||
if (speaker != nullptr) {
|
||||
speaker->setLoop(lua::toboolean(L, 2));
|
||||
@ -209,7 +209,7 @@ static int l_audio_set_loop(lua_State* L) {
|
||||
}
|
||||
|
||||
/// @brief audio.set_volume(speakerid: integer, value: number) -> nil
|
||||
static int l_audio_set_volume(lua_State* L) {
|
||||
static int l_audio_set_volume(lua::State* L) {
|
||||
auto speaker = audio::get_speaker(lua::tointeger(L, 1));
|
||||
if (speaker != nullptr) {
|
||||
speaker->setVolume(static_cast<float>(lua::tonumber(L, 2)));
|
||||
@ -218,7 +218,7 @@ static int l_audio_set_volume(lua_State* L) {
|
||||
}
|
||||
|
||||
/// @brief audio.set_pitch(speakerid: integer, value: number) -> nil
|
||||
static int l_audio_set_pitch(lua_State* L) {
|
||||
static int l_audio_set_pitch(lua::State* L) {
|
||||
auto speaker = audio::get_speaker(lua::tointeger(L, 1));
|
||||
if (speaker != nullptr) {
|
||||
speaker->setPitch(static_cast<float>(lua::tonumber(L, 2)));
|
||||
@ -227,7 +227,7 @@ static int l_audio_set_pitch(lua_State* L) {
|
||||
}
|
||||
|
||||
/// @brief audio.set_time(speakerid: integer, value: number) -> nil
|
||||
static int l_audio_set_time(lua_State* L) {
|
||||
static int l_audio_set_time(lua::State* L) {
|
||||
auto speaker = audio::get_speaker(lua::tointeger(L, 1));
|
||||
if (speaker != nullptr) {
|
||||
speaker->setTime(static_cast<audio::duration_t>(lua::tonumber(L, 2)));
|
||||
@ -236,7 +236,7 @@ static int l_audio_set_time(lua_State* L) {
|
||||
}
|
||||
|
||||
/// @brief audio.set_position(speakerid: integer, x: number, y: number, z: number) -> nil
|
||||
static int l_audio_set_position(lua_State* L) {
|
||||
static int l_audio_set_position(lua::State* L) {
|
||||
auto speaker = audio::get_speaker(lua::tointeger(L, 1));
|
||||
if (speaker != nullptr) {
|
||||
auto x = lua::tonumber(L, 2);
|
||||
@ -252,7 +252,7 @@ static int l_audio_set_position(lua_State* L) {
|
||||
}
|
||||
|
||||
/// @brief audio.set_velocity(speakerid: integer, x: number, y: number, z: number) -> nil
|
||||
static int l_audio_set_velocity(lua_State* L) {
|
||||
static int l_audio_set_velocity(lua::State* L) {
|
||||
auto speaker = audio::get_speaker(lua::tointeger(L, 1));
|
||||
if (speaker != nullptr) {
|
||||
auto x = lua::tonumber(L, 2);
|
||||
@ -268,7 +268,7 @@ static int l_audio_set_velocity(lua_State* L) {
|
||||
}
|
||||
|
||||
/// @brief audio.is_playing(speakerid: integer) -> bool
|
||||
static int l_audio_is_playing(lua_State* L) {
|
||||
static int l_audio_is_playing(lua::State* L) {
|
||||
auto speaker = audio::get_speaker(lua::tointeger(L, 1));
|
||||
if (speaker != nullptr) {
|
||||
return lua::pushboolean(L, speaker->isPlaying());
|
||||
@ -277,7 +277,7 @@ static int l_audio_is_playing(lua_State* L) {
|
||||
}
|
||||
|
||||
/// @brief audio.is_paused(speakerid: integer) -> bool
|
||||
static int l_audio_is_paused(lua_State* L) {
|
||||
static int l_audio_is_paused(lua::State* L) {
|
||||
auto speaker = audio::get_speaker(lua::tointeger(L, 1));
|
||||
if (speaker != nullptr) {
|
||||
return lua::pushboolean(L, speaker->isPaused());
|
||||
@ -286,7 +286,7 @@ static int l_audio_is_paused(lua_State* L) {
|
||||
}
|
||||
|
||||
/// @brief audio.is_loop(speakerid: integer) -> bool
|
||||
static int l_audio_is_loop(lua_State* L) {
|
||||
static int l_audio_is_loop(lua::State* L) {
|
||||
auto speaker = audio::get_speaker(lua::tointeger(L, 1));
|
||||
if (speaker != nullptr) {
|
||||
return lua::pushboolean(L, speaker->isLoop());
|
||||
@ -295,7 +295,7 @@ static int l_audio_is_loop(lua_State* L) {
|
||||
}
|
||||
|
||||
/// @brief audio.get_volume(speakerid: integer) -> number
|
||||
static int l_audio_get_volume(lua_State* L) {
|
||||
static int l_audio_get_volume(lua::State* L) {
|
||||
auto speaker = audio::get_speaker(lua::tointeger(L, 1));
|
||||
if (speaker != nullptr) {
|
||||
return lua::pushnumber(L, speaker->getVolume());
|
||||
@ -304,7 +304,7 @@ static int l_audio_get_volume(lua_State* L) {
|
||||
}
|
||||
|
||||
/// @brief audio.get_pitch(speakerid: integer) -> number
|
||||
static int l_audio_get_pitch(lua_State* L) {
|
||||
static int l_audio_get_pitch(lua::State* L) {
|
||||
auto speaker = audio::get_speaker(lua::tointeger(L, 1));
|
||||
if (speaker != nullptr) {
|
||||
return lua::pushnumber(L, speaker->getPitch());
|
||||
@ -313,7 +313,7 @@ static int l_audio_get_pitch(lua_State* L) {
|
||||
}
|
||||
|
||||
/// @brief audio.get_time(speakerid: integer) -> number
|
||||
static int l_audio_get_time(lua_State* L) {
|
||||
static int l_audio_get_time(lua::State* L) {
|
||||
auto speaker = audio::get_speaker(lua::tointeger(L, 1));
|
||||
if (speaker != nullptr) {
|
||||
return lua::pushnumber(L, speaker->getTime());
|
||||
@ -322,7 +322,7 @@ static int l_audio_get_time(lua_State* L) {
|
||||
}
|
||||
|
||||
/// @brief audio.get_duration(speakerid: integer) -> number
|
||||
static int l_audio_get_duration(lua_State* L) {
|
||||
static int l_audio_get_duration(lua::State* L) {
|
||||
auto speaker = audio::get_speaker(lua::tointeger(L, 1));
|
||||
if (speaker != nullptr) {
|
||||
return lua::pushnumber(L, speaker->getDuration());
|
||||
@ -331,7 +331,7 @@ static int l_audio_get_duration(lua_State* L) {
|
||||
}
|
||||
|
||||
/// @brief audio.get_position(speakerid: integer) -> number, number, number
|
||||
static int l_audio_get_position(lua_State* L) {
|
||||
static int l_audio_get_position(lua::State* L) {
|
||||
auto speaker = audio::get_speaker(lua::tointeger(L, 1));
|
||||
if (speaker != nullptr) {
|
||||
return lua::pushvec3(L, speaker->getPosition());
|
||||
@ -340,7 +340,7 @@ static int l_audio_get_position(lua_State* L) {
|
||||
}
|
||||
|
||||
/// @brief audio.get_velocity(speakerid: integer) -> number, number, number
|
||||
static int l_audio_get_velocity(lua_State* L) {
|
||||
static int l_audio_get_velocity(lua::State* L) {
|
||||
auto speaker = audio::get_speaker(lua::tointeger(L, 1));
|
||||
if (speaker != nullptr) {
|
||||
return lua::pushvec3(L, speaker->getVelocity());
|
||||
@ -349,12 +349,12 @@ static int l_audio_get_velocity(lua_State* L) {
|
||||
}
|
||||
|
||||
// @brief audio.count_speakers() -> integer
|
||||
static int l_audio_count_speakers(lua_State* L) {
|
||||
static int l_audio_count_speakers(lua::State* L) {
|
||||
return lua::pushinteger(L, audio::count_speakers());
|
||||
}
|
||||
|
||||
// @brief audio.count_streams() -> integer
|
||||
static int l_audio_count_streams(lua_State* L) {
|
||||
static int l_audio_count_streams(lua::State* L) {
|
||||
return lua::pushinteger(L, audio::count_streams());
|
||||
}
|
||||
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
|
||||
using namespace scripting;
|
||||
|
||||
static Block* require_block(lua_State* L) {
|
||||
static Block* require_block(lua::State* L) {
|
||||
auto indices = content->getIndices();
|
||||
auto id = lua::tointeger(L, 1);
|
||||
if (static_cast<size_t>(id) >= indices->countBlockDefs()) {
|
||||
@ -20,21 +20,21 @@ static Block* require_block(lua_State* L) {
|
||||
return indices->getBlockDef(id);
|
||||
}
|
||||
|
||||
static int l_name(lua_State* L) {
|
||||
static int l_name(lua::State* L) {
|
||||
if (auto def = require_block(L)) {
|
||||
return lua::pushstring(L, def->name);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_material(lua_State* L) {
|
||||
static int l_material(lua::State* L) {
|
||||
if (auto def = require_block(L)) {
|
||||
return lua::pushstring(L, def->material);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_is_solid_at(lua_State* L) {
|
||||
static int l_is_solid_at(lua::State* L) {
|
||||
auto x = lua::tointeger(L, 1);
|
||||
auto y = lua::tointeger(L, 2);
|
||||
auto z = lua::tointeger(L, 3);
|
||||
@ -42,30 +42,30 @@ static int l_is_solid_at(lua_State* L) {
|
||||
return lua::pushboolean(L, level->chunks->isSolidBlock(x, y, z));
|
||||
}
|
||||
|
||||
static int l_count(lua_State* L) {
|
||||
static int l_count(lua::State* L) {
|
||||
return lua::pushinteger(L, indices->countBlockDefs());
|
||||
}
|
||||
|
||||
static int l_index(lua_State* L) {
|
||||
static int l_index(lua::State* L) {
|
||||
auto name = lua::require_string(L, 1);
|
||||
return lua::pushinteger(L, content->requireBlock(name).rt.id);
|
||||
}
|
||||
|
||||
static int l_is_extended(lua_State* L) {
|
||||
static int l_is_extended(lua::State* L) {
|
||||
if (auto def = require_block(L)) {
|
||||
return lua::pushboolean(L, def->rt.extended);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_get_size(lua_State* L) {
|
||||
static int l_get_size(lua::State* L) {
|
||||
if (auto def = require_block(L)) {
|
||||
return lua::pushivec3(L, def->size.x, def->size.y, def->size.z);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_is_segment(lua_State* L) {
|
||||
static int l_is_segment(lua::State* L) {
|
||||
auto x = lua::tointeger(L, 1);
|
||||
auto y = lua::tointeger(L, 2);
|
||||
auto z = lua::tointeger(L, 3);
|
||||
@ -73,7 +73,7 @@ static int l_is_segment(lua_State* L) {
|
||||
return lua::pushboolean(L, vox->state.segment);
|
||||
}
|
||||
|
||||
static int l_seek_origin(lua_State* L) {
|
||||
static int l_seek_origin(lua::State* L) {
|
||||
auto x = lua::tointeger(L, 1);
|
||||
auto y = lua::tointeger(L, 2);
|
||||
auto z = lua::tointeger(L, 3);
|
||||
@ -82,7 +82,7 @@ static int l_seek_origin(lua_State* L) {
|
||||
return lua::pushivec3(L, level->chunks->seekOrigin({x, y, z}, def, vox->state));
|
||||
}
|
||||
|
||||
static int l_set(lua_State* L) {
|
||||
static int l_set(lua::State* L) {
|
||||
auto x = lua::tointeger(L, 1);
|
||||
auto y = lua::tointeger(L, 2);
|
||||
auto z = lua::tointeger(L, 3);
|
||||
@ -103,7 +103,7 @@ static int l_set(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_get(lua_State* L) {
|
||||
static int l_get(lua::State* L) {
|
||||
auto x = lua::tointeger(L, 1);
|
||||
auto y = lua::tointeger(L, 2);
|
||||
auto z = lua::tointeger(L, 3);
|
||||
@ -112,7 +112,7 @@ static int l_get(lua_State* L) {
|
||||
return lua::pushinteger(L, id);
|
||||
}
|
||||
|
||||
static int l_get_x(lua_State* L) {
|
||||
static int l_get_x(lua::State* L) {
|
||||
auto x = lua::tointeger(L, 1);
|
||||
auto y = lua::tointeger(L, 2);
|
||||
auto z = lua::tointeger(L, 3);
|
||||
@ -129,7 +129,7 @@ static int l_get_x(lua_State* L) {
|
||||
}
|
||||
}
|
||||
|
||||
static int l_get_y(lua_State* L) {
|
||||
static int l_get_y(lua::State* L) {
|
||||
auto x = lua::tointeger(L, 1);
|
||||
auto y = lua::tointeger(L, 2);
|
||||
auto z = lua::tointeger(L, 3);
|
||||
@ -146,7 +146,7 @@ static int l_get_y(lua_State* L) {
|
||||
}
|
||||
}
|
||||
|
||||
static int l_get_z(lua_State* L) {
|
||||
static int l_get_z(lua::State* L) {
|
||||
auto x = lua::tointeger(L, 1);
|
||||
auto y = lua::tointeger(L, 2);
|
||||
auto z = lua::tointeger(L, 3);
|
||||
@ -163,7 +163,7 @@ static int l_get_z(lua_State* L) {
|
||||
}
|
||||
}
|
||||
|
||||
static int l_get_rotation(lua_State* L) {
|
||||
static int l_get_rotation(lua::State* L) {
|
||||
auto x = lua::tointeger(L, 1);
|
||||
auto y = lua::tointeger(L, 2);
|
||||
auto z = lua::tointeger(L, 3);
|
||||
@ -172,7 +172,7 @@ static int l_get_rotation(lua_State* L) {
|
||||
return lua::pushinteger(L, rotation);
|
||||
}
|
||||
|
||||
static int l_set_rotation(lua_State* L) {
|
||||
static int l_set_rotation(lua::State* L) {
|
||||
auto x = lua::tointeger(L, 1);
|
||||
auto y = lua::tointeger(L, 2);
|
||||
auto z = lua::tointeger(L, 3);
|
||||
@ -181,7 +181,7 @@ static int l_set_rotation(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_get_states(lua_State* L) {
|
||||
static int l_get_states(lua::State* L) {
|
||||
auto x = lua::tointeger(L, 1);
|
||||
auto y = lua::tointeger(L, 2);
|
||||
auto z = lua::tointeger(L, 3);
|
||||
@ -190,7 +190,7 @@ static int l_get_states(lua_State* L) {
|
||||
return lua::pushinteger(L, states);
|
||||
}
|
||||
|
||||
static int l_set_states(lua_State* L) {
|
||||
static int l_set_states(lua::State* L) {
|
||||
auto x = lua::tointeger(L, 1);
|
||||
auto y = lua::tointeger(L, 2);
|
||||
auto z = lua::tointeger(L, 3);
|
||||
@ -206,7 +206,7 @@ static int l_set_states(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_get_user_bits(lua_State* L) {
|
||||
static int l_get_user_bits(lua::State* L) {
|
||||
auto x = lua::tointeger(L, 1);
|
||||
auto y = lua::tointeger(L, 2);
|
||||
auto z = lua::tointeger(L, 3);
|
||||
@ -222,7 +222,7 @@ static int l_get_user_bits(lua_State* L) {
|
||||
return lua::pushinteger(L, data);
|
||||
}
|
||||
|
||||
static int l_set_user_bits(lua_State* L) {
|
||||
static int l_set_user_bits(lua::State* L) {
|
||||
auto x = lua::tointeger(L, 1);
|
||||
auto y = lua::tointeger(L, 2);
|
||||
auto z = lua::tointeger(L, 3);
|
||||
@ -245,14 +245,14 @@ static int l_set_user_bits(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_is_replaceable_at(lua_State* L) {
|
||||
static int l_is_replaceable_at(lua::State* L) {
|
||||
auto x = lua::tointeger(L, 1);
|
||||
auto y = lua::tointeger(L, 2);
|
||||
auto z = lua::tointeger(L, 3);
|
||||
return lua::pushboolean(L, level->chunks->isReplaceableBlock(x, y, z));
|
||||
}
|
||||
|
||||
static int l_caption(lua_State* L) {
|
||||
static int l_caption(lua::State* L) {
|
||||
if (auto def = require_block(L)) {
|
||||
return lua::pushstring(L, def->caption);
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
|
||||
using namespace scripting;
|
||||
|
||||
static int l_add_command(lua_State* L) {
|
||||
static int l_add_command(lua::State* L) {
|
||||
if (!lua::isfunction(L, 3)) {
|
||||
throw std::runtime_error("invalid callback");
|
||||
}
|
||||
@ -26,21 +26,21 @@ static int l_add_command(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_execute(lua_State* L) {
|
||||
static int l_execute(lua::State* L) {
|
||||
auto prompt = lua::require_string(L, 1);
|
||||
auto result = engine->getCommandsInterpreter()->execute(prompt);
|
||||
lua::pushvalue(L, result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_set(lua_State* L) {
|
||||
static int l_set(lua::State* L) {
|
||||
auto name = lua::require_string(L, 1);
|
||||
auto value = lua::tovalue(L, 2);
|
||||
(*engine->getCommandsInterpreter())[name] = value;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_get_commands_list(lua_State* L) {
|
||||
static int l_get_commands_list(lua::State* L) {
|
||||
auto interpreter = engine->getCommandsInterpreter();
|
||||
auto repo = interpreter->getRepository();
|
||||
const auto& commands = repo->getCommands();
|
||||
@ -54,7 +54,7 @@ static int l_get_commands_list(lua_State* L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_get_command_info(lua_State* L) {
|
||||
static int l_get_command_info(lua::State* L) {
|
||||
auto name = lua::require_string(L, 1);
|
||||
auto interpreter = engine->getCommandsInterpreter();
|
||||
auto repo = interpreter->getRepository();
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
|
||||
using namespace scripting;
|
||||
|
||||
static int l_new_world(lua_State* L) {
|
||||
static int l_new_world(lua::State* L) {
|
||||
auto name = lua::require_string(L, 1);
|
||||
auto seed = lua::require_string(L, 2);
|
||||
auto generator = lua::require_string(L, 3);
|
||||
@ -26,7 +26,7 @@ static int l_new_world(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_open_world(lua_State* L) {
|
||||
static int l_open_world(lua::State* L) {
|
||||
auto name = lua::require_string(L, 1);
|
||||
|
||||
auto controller = engine->getController();
|
||||
@ -34,13 +34,13 @@ static int l_open_world(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_reopen_world(lua_State*) {
|
||||
static int l_reopen_world(lua::State*) {
|
||||
auto controller = engine->getController();
|
||||
controller->reopenWorld(level->getWorld());
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_close_world(lua_State* L) {
|
||||
static int l_close_world(lua::State* L) {
|
||||
if (controller == nullptr) {
|
||||
throw std::runtime_error("no world open");
|
||||
}
|
||||
@ -55,14 +55,14 @@ static int l_close_world(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_delete_world(lua_State* L) {
|
||||
static int l_delete_world(lua::State* L) {
|
||||
auto name = lua::require_string(L, 1);
|
||||
auto controller = engine->getController();
|
||||
controller->deleteWorld(name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_reconfig_packs(lua_State* L) {
|
||||
static int l_reconfig_packs(lua::State* L) {
|
||||
if (!lua::istable(L, 1)) {
|
||||
throw std::runtime_error("strings array expected as the first argument");
|
||||
}
|
||||
@ -95,26 +95,26 @@ static int l_reconfig_packs(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_get_setting(lua_State* L) {
|
||||
static int l_get_setting(lua::State* L) {
|
||||
auto name = lua::require_string(L, 1);
|
||||
const auto value = engine->getSettingsHandler().getValue(name);
|
||||
return lua::pushvalue(L, value);
|
||||
}
|
||||
|
||||
static int l_set_setting(lua_State* L) {
|
||||
static int l_set_setting(lua::State* L) {
|
||||
auto name = lua::require_string(L, 1);
|
||||
const auto value = lua::tovalue(L, 2);
|
||||
engine->getSettingsHandler().setValue(name, value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_str_setting(lua_State* L) {
|
||||
static int l_str_setting(lua::State* L) {
|
||||
auto name = lua::require_string(L, 1);
|
||||
const auto string = engine->getSettingsHandler().toString(name);
|
||||
return lua::pushstring(L, string);
|
||||
}
|
||||
|
||||
static int l_get_setting_info(lua_State* L) {
|
||||
static int l_get_setting_info(lua::State* L) {
|
||||
auto name = lua::require_string(L, 1);
|
||||
auto setting = engine->getSettingsHandler().getSetting(name);
|
||||
lua::createtable(L, 0, 1);
|
||||
@ -136,16 +136,16 @@ static int l_get_setting_info(lua_State* L) {
|
||||
throw std::runtime_error("unsupported setting type");
|
||||
}
|
||||
|
||||
static int l_quit(lua_State*) {
|
||||
static int l_quit(lua::State*) {
|
||||
Window::setShouldClose(true);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_get_default_generator(lua_State* L) {
|
||||
static int l_get_default_generator(lua::State* L) {
|
||||
return lua::pushstring(L, WorldGenerators::getDefaultGeneratorID());
|
||||
}
|
||||
|
||||
static int l_get_generators(lua_State* L) {
|
||||
static int l_get_generators(lua::State* L) {
|
||||
const auto& generators = WorldGenerators::getGeneratorsIDs();
|
||||
lua::createtable(L, generators.size(), 0);
|
||||
|
||||
|
||||
@ -23,7 +23,7 @@ static fs::path resolve_path_soft(const std::string& path) {
|
||||
return engine->getPaths()->resolve(path, false);
|
||||
}
|
||||
|
||||
static int l_file_find(lua_State* L) {
|
||||
static int l_file_find(lua::State* L) {
|
||||
auto path = lua::require_string(L, 1);
|
||||
try {
|
||||
return lua::pushstring(L, engine->getResPaths()->findRaw(path));
|
||||
@ -32,12 +32,12 @@ static int l_file_find(lua_State* L) {
|
||||
}
|
||||
}
|
||||
|
||||
static int l_file_resolve(lua_State* L) {
|
||||
static int l_file_resolve(lua::State* L) {
|
||||
fs::path path = resolve_path(lua::require_string(L, 1));
|
||||
return lua::pushstring(L, path.u8string());
|
||||
}
|
||||
|
||||
static int l_file_read(lua_State* L) {
|
||||
static int l_file_read(lua::State* L) {
|
||||
fs::path path = resolve_path(lua::require_string(L, 1));
|
||||
if (fs::is_regular_file(path)) {
|
||||
return lua::pushstring(L, files::read_string(path));
|
||||
@ -45,14 +45,14 @@ static int l_file_read(lua_State* L) {
|
||||
throw std::runtime_error("file does not exists "+util::quote(path.u8string()));
|
||||
}
|
||||
|
||||
static int l_file_write(lua_State* L) {
|
||||
static int l_file_write(lua::State* L) {
|
||||
fs::path path = resolve_path(lua::require_string(L, 1));
|
||||
std::string text = lua::require_string(L, 2);
|
||||
files::write_string(path, text);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_file_remove(lua_State* L) {
|
||||
static int l_file_remove(lua::State* L) {
|
||||
std::string rawpath = lua::require_string(L, 1);
|
||||
fs::path path = resolve_path(rawpath);
|
||||
auto entryPoint = rawpath.substr(0, rawpath.find(':'));
|
||||
@ -62,7 +62,7 @@ static int l_file_remove(lua_State* L) {
|
||||
return lua::pushboolean(L, fs::remove(path));
|
||||
}
|
||||
|
||||
static int l_file_remove_tree(lua_State* L) {
|
||||
static int l_file_remove_tree(lua::State* L) {
|
||||
std::string rawpath = lua::require_string(L, 1);
|
||||
fs::path path = resolve_path(rawpath);
|
||||
auto entryPoint = rawpath.substr(0, rawpath.find(':'));
|
||||
@ -72,22 +72,22 @@ static int l_file_remove_tree(lua_State* L) {
|
||||
return lua::pushinteger(L, fs::remove_all(path));
|
||||
}
|
||||
|
||||
static int l_file_exists(lua_State* L) {
|
||||
static int l_file_exists(lua::State* L) {
|
||||
fs::path path = resolve_path_soft(lua::require_string(L, 1));
|
||||
return lua::pushboolean(L, fs::exists(path));
|
||||
}
|
||||
|
||||
static int l_file_isfile(lua_State* L) {
|
||||
static int l_file_isfile(lua::State* L) {
|
||||
fs::path path = resolve_path_soft(lua::require_string(L, 1));
|
||||
return lua::pushboolean(L, fs::is_regular_file(path));
|
||||
}
|
||||
|
||||
static int l_file_isdir(lua_State* L) {
|
||||
static int l_file_isdir(lua::State* L) {
|
||||
fs::path path = resolve_path_soft(lua::require_string(L, 1));
|
||||
return lua::pushboolean(L, fs::is_directory(path));
|
||||
}
|
||||
|
||||
static int l_file_length(lua_State* L) {
|
||||
static int l_file_length(lua::State* L) {
|
||||
fs::path path = resolve_path(lua::require_string(L, 1));
|
||||
if (fs::exists(path)){
|
||||
return lua::pushinteger(L, fs::file_size(path));
|
||||
@ -96,17 +96,17 @@ static int l_file_length(lua_State* L) {
|
||||
}
|
||||
}
|
||||
|
||||
static int l_file_mkdir(lua_State* L) {
|
||||
static int l_file_mkdir(lua::State* L) {
|
||||
fs::path path = resolve_path(lua::require_string(L, 1));
|
||||
return lua::pushboolean(L, fs::create_directory(path));
|
||||
}
|
||||
|
||||
static int l_file_mkdirs(lua_State* L) {
|
||||
static int l_file_mkdirs(lua::State* L) {
|
||||
fs::path path = resolve_path(lua::require_string(L, 1));
|
||||
return lua::pushboolean(L, fs::create_directories(path));
|
||||
}
|
||||
|
||||
static int l_file_read_bytes(lua_State* L) {
|
||||
static int l_file_read_bytes(lua::State* L) {
|
||||
fs::path path = resolve_path(lua::require_string(L, 1));
|
||||
if (fs::is_regular_file(path)) {
|
||||
size_t length = static_cast<size_t>(fs::file_size(path));
|
||||
@ -125,12 +125,12 @@ static int l_file_read_bytes(lua_State* L) {
|
||||
throw std::runtime_error("file does not exists "+util::quote(path.u8string()));
|
||||
}
|
||||
|
||||
static int read_bytes_from_table(lua_State* L, int tableIndex, std::vector<ubyte>& bytes) {
|
||||
static int read_bytes_from_table(lua::State* L, int tableIndex, std::vector<ubyte>& bytes) {
|
||||
if(!lua::istable(L, tableIndex)) {
|
||||
throw std::runtime_error("table expected");
|
||||
} else {
|
||||
lua::pushnil(L);
|
||||
while(lua_next(L, tableIndex - 1) != 0) {
|
||||
while(lua::next(L, tableIndex - 1) != 0) {
|
||||
const int byte = lua::tointeger(L, -1);
|
||||
if(byte < 0 || byte > 255) {
|
||||
throw std::runtime_error("invalid byte '"+std::to_string(byte)+"'");
|
||||
@ -142,7 +142,7 @@ static int read_bytes_from_table(lua_State* L, int tableIndex, std::vector<ubyte
|
||||
}
|
||||
}
|
||||
|
||||
static int l_file_write_bytes(lua_State* L) {
|
||||
static int l_file_write_bytes(lua::State* L) {
|
||||
int pathIndex = 1;
|
||||
|
||||
if(!lua::isstring(L, pathIndex)) {
|
||||
@ -162,7 +162,7 @@ static int l_file_write_bytes(lua_State* L) {
|
||||
}
|
||||
}
|
||||
|
||||
static int l_file_list_all_res(lua_State* L, const std::string& path) {
|
||||
static int l_file_list_all_res(lua::State* L, const std::string& path) {
|
||||
auto files = engine->getResPaths()->listdirRaw(path);
|
||||
lua::createtable(L, files.size(), 0);
|
||||
for (size_t i = 0; i < files.size(); i++) {
|
||||
@ -172,7 +172,7 @@ static int l_file_list_all_res(lua_State* L, const std::string& path) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_file_list(lua_State* L) {
|
||||
static int l_file_list(lua::State* L) {
|
||||
std::string dirname = lua::require_string(L, 1);
|
||||
if (dirname.find(':') == std::string::npos) {
|
||||
return l_file_list_all_res(L, dirname);
|
||||
@ -193,7 +193,7 @@ static int l_file_list(lua_State* L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_file_gzip_compress(lua_State* L) {
|
||||
static int l_file_gzip_compress(lua::State* L) {
|
||||
fs::path path = resolve_path(lua::require_string(L, 1));
|
||||
if (fs::is_regular_file(path)) {
|
||||
size_t length = static_cast<size_t>(fs::file_size(path));
|
||||
@ -205,7 +205,7 @@ static int l_file_gzip_compress(lua_State* L) {
|
||||
throw std::runtime_error("file does not exist " + util::quote(path.u8string()));
|
||||
}
|
||||
|
||||
static int l_file_gzip_decompress(lua_State* L) {
|
||||
static int l_file_gzip_decompress(lua::State* L) {
|
||||
fs::path path = resolve_path(lua::require_string(L, 1));
|
||||
if (fs::is_regular_file(path)) {
|
||||
size_t length = static_cast<size_t>(fs::file_size(path));
|
||||
|
||||
@ -26,7 +26,7 @@ struct DocumentNode {
|
||||
std::shared_ptr<UINode> node;
|
||||
};
|
||||
|
||||
static DocumentNode getDocumentNode(lua_State*, const std::string& name, const std::string& nodeName) {
|
||||
static DocumentNode getDocumentNode(lua::State*, const std::string& name, const std::string& nodeName) {
|
||||
auto doc = engine->getAssets()->getLayout(name);
|
||||
if (doc == nullptr) {
|
||||
throw std::runtime_error("document '"+name+"' not found");
|
||||
@ -38,31 +38,31 @@ static DocumentNode getDocumentNode(lua_State*, const std::string& name, const s
|
||||
return {doc, node};
|
||||
}
|
||||
|
||||
static DocumentNode getDocumentNode(lua_State* L, int idx=1) {
|
||||
lua_getfield(L, idx, "docname");
|
||||
lua_getfield(L, idx, "name");
|
||||
static DocumentNode getDocumentNode(lua::State* L, int idx=1) {
|
||||
lua::getfield(L, "docname", idx);
|
||||
lua::getfield(L, "name", idx);
|
||||
auto docname = lua::require_string(L, -2);
|
||||
auto name = lua::require_string(L, -1);
|
||||
auto node = getDocumentNode(L, docname, name);
|
||||
lua_pop(L, 2);
|
||||
lua::pop(L, 2);
|
||||
return node;
|
||||
}
|
||||
|
||||
static int l_menu_back(lua_State* L) {
|
||||
static int l_menu_back(lua::State* L) {
|
||||
auto node = getDocumentNode(L);
|
||||
auto menu = dynamic_cast<Menu*>(node.node.get());
|
||||
menu->back();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_menu_reset(lua_State* L) {
|
||||
static int l_menu_reset(lua::State* L) {
|
||||
auto node = getDocumentNode(L);
|
||||
auto menu = dynamic_cast<Menu*>(node.node.get());
|
||||
menu->reset();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_textbox_paste(lua_State* L) {
|
||||
static int l_textbox_paste(lua::State* L) {
|
||||
auto node = getDocumentNode(L);
|
||||
auto box = dynamic_cast<TextBox*>(node.node.get());
|
||||
auto text = lua::require_string(L, 2);
|
||||
@ -70,7 +70,7 @@ static int l_textbox_paste(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_container_add(lua_State* L) {
|
||||
static int l_container_add(lua::State* L) {
|
||||
auto docnode = getDocumentNode(L);
|
||||
auto node = dynamic_cast<Container*>(docnode.node.get());
|
||||
auto xmlsrc = lua::require_string(L, 2);
|
||||
@ -84,7 +84,7 @@ static int l_container_add(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_node_destruct(lua_State* L) {
|
||||
static int l_node_destruct(lua::State* L) {
|
||||
auto docnode = getDocumentNode(L);
|
||||
auto node = std::dynamic_pointer_cast<Container>(docnode.node);
|
||||
engine->getGUI()->postRunnable([node]() {
|
||||
@ -96,7 +96,7 @@ static int l_node_destruct(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_container_clear(lua_State* L) {
|
||||
static int l_container_clear(lua::State* L) {
|
||||
auto node = getDocumentNode(L, 1);
|
||||
if (auto container = std::dynamic_pointer_cast<Container>(node.node)) {
|
||||
container->clear();
|
||||
@ -104,7 +104,7 @@ static int l_container_clear(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_container_set_interval(lua_State* L) {
|
||||
static int l_container_set_interval(lua::State* L) {
|
||||
auto node = getDocumentNode(L, 1);
|
||||
auto interval = lua::tointeger(L, 2) / 1000.0f;
|
||||
if (auto container = std::dynamic_pointer_cast<Container>(node.node)) {
|
||||
@ -115,14 +115,14 @@ static int l_container_set_interval(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_move_into(lua_State* L) {
|
||||
static int l_move_into(lua::State* L) {
|
||||
auto node = getDocumentNode(L, 1);
|
||||
auto dest = getDocumentNode(L, 2);
|
||||
UINode::moveInto(node.node, std::dynamic_pointer_cast<Container>(dest.node));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int p_get_inventory(UINode* node, lua_State* L) {
|
||||
static int p_get_inventory(UINode* node, lua::State* L) {
|
||||
if (auto inventory = dynamic_cast<InventoryView*>(node)) {
|
||||
auto inv = inventory->getInventory();
|
||||
return lua::pushinteger(L, inv ? inv->getId() : 0);
|
||||
@ -130,35 +130,35 @@ static int p_get_inventory(UINode* node, lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int p_get_reset(UINode* node, lua_State* L) {
|
||||
static int p_get_reset(UINode* node, lua::State* L) {
|
||||
if (dynamic_cast<Menu*>(node)) {
|
||||
return lua::pushcfunction(L, l_menu_reset);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int p_get_back(UINode* node, lua_State* L) {
|
||||
static int p_get_back(UINode* node, lua::State* L) {
|
||||
if (dynamic_cast<Menu*>(node)) {
|
||||
return lua::pushcfunction(L, l_menu_back);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int p_get_paste(UINode* node, lua_State* L) {
|
||||
static int p_get_paste(UINode* node, lua::State* L) {
|
||||
if (dynamic_cast<TextBox*>(node)) {
|
||||
return lua::pushcfunction(L, l_textbox_paste);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int p_get_page(UINode* node, lua_State* L) {
|
||||
static int p_get_page(UINode* node, lua::State* L) {
|
||||
if (auto menu = dynamic_cast<Menu*>(node)) {
|
||||
return lua::pushstring(L, menu->getCurrent().name);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int p_is_checked(UINode* node, lua_State* L) {
|
||||
static int p_is_checked(UINode* node, lua::State* L) {
|
||||
if (auto box = dynamic_cast<CheckBox*>(node)) {
|
||||
return lua::pushboolean(L, box->isChecked());
|
||||
} else if (auto box = dynamic_cast<FullCheckBox*>(node)) {
|
||||
@ -167,70 +167,70 @@ static int p_is_checked(UINode* node, lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int p_get_value(UINode* node, lua_State* L) {
|
||||
static int p_get_value(UINode* node, lua::State* L) {
|
||||
if (auto bar = dynamic_cast<TrackBar*>(node)) {
|
||||
return lua::pushnumber(L, bar->getValue());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int p_get_min(UINode* node, lua_State* L) {
|
||||
static int p_get_min(UINode* node, lua::State* L) {
|
||||
if (auto bar = dynamic_cast<TrackBar*>(node)) {
|
||||
return lua::pushnumber(L, bar->getMin());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int p_get_max(UINode* node, lua_State* L) {
|
||||
static int p_get_max(UINode* node, lua::State* L) {
|
||||
if (auto bar = dynamic_cast<TrackBar*>(node)) {
|
||||
return lua::pushnumber(L, bar->getMax());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int p_get_step(UINode* node, lua_State* L) {
|
||||
static int p_get_step(UINode* node, lua::State* L) {
|
||||
if (auto bar = dynamic_cast<TrackBar*>(node)) {
|
||||
return lua::pushnumber(L, bar->getStep());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int p_get_track_width(UINode* node, lua_State* L) {
|
||||
static int p_get_track_width(UINode* node, lua::State* L) {
|
||||
if (auto bar = dynamic_cast<TrackBar*>(node)) {
|
||||
return lua::pushnumber(L, bar->getTrackWidth());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int p_get_track_color(UINode* node, lua_State* L) {
|
||||
static int p_get_track_color(UINode* node, lua::State* L) {
|
||||
if (auto bar = dynamic_cast<TrackBar*>(node)) {
|
||||
return lua::pushcolor_arr(L, bar->getTrackColor());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int p_is_valid(UINode* node, lua_State* L) {
|
||||
static int p_is_valid(UINode* node, lua::State* L) {
|
||||
if (auto box = dynamic_cast<TextBox*>(node)) {
|
||||
return lua::pushboolean(L, box->validate());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int p_get_caret(UINode* node, lua_State* L) {
|
||||
static int p_get_caret(UINode* node, lua::State* L) {
|
||||
if (auto box = dynamic_cast<TextBox*>(node)) {
|
||||
return lua::pushinteger(L, static_cast<integer_t>(box->getCaret()));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int p_get_placeholder(UINode* node, lua_State* L) {
|
||||
static int p_get_placeholder(UINode* node, lua::State* L) {
|
||||
if (auto box = dynamic_cast<TextBox*>(node)) {
|
||||
return lua::pushwstring(L, box->getPlaceholder());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int p_get_text(UINode* node, lua_State* L) {
|
||||
static int p_get_text(UINode* node, lua::State* L) {
|
||||
if (auto button = dynamic_cast<Button*>(node)) {
|
||||
return lua::pushwstring(L, button->getText());
|
||||
} else if (auto label = dynamic_cast<Label*>(node)) {
|
||||
@ -241,93 +241,93 @@ static int p_get_text(UINode* node, lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int p_get_editable(UINode* node, lua_State* L) {
|
||||
static int p_get_editable(UINode* node, lua::State* L) {
|
||||
if (auto box = dynamic_cast<TextBox*>(node)) {
|
||||
return lua::pushboolean(L, box->isEditable());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int p_get_src(UINode* node, lua_State* L) {
|
||||
static int p_get_src(UINode* node, lua::State* L) {
|
||||
if (auto image = dynamic_cast<Image*>(node)) {
|
||||
return lua::pushstring(L, image->getTexture());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int p_get_add(UINode* node, lua_State* L) {
|
||||
static int p_get_add(UINode* node, lua::State* L) {
|
||||
if (dynamic_cast<Container*>(node)) {
|
||||
return lua::pushcfunction(L, lua::wrap<l_container_add>);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int p_get_destruct(UINode*, lua_State* L) {
|
||||
static int p_get_destruct(UINode*, lua::State* L) {
|
||||
return lua::pushcfunction(L, lua::wrap<l_node_destruct>);
|
||||
}
|
||||
|
||||
static int p_get_clear(UINode* node, lua_State* L) {
|
||||
static int p_get_clear(UINode* node, lua::State* L) {
|
||||
if (dynamic_cast<Container*>(node)) {
|
||||
return lua::pushcfunction(L, lua::wrap<l_container_clear>);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int p_set_interval(UINode* node, lua_State* L) {
|
||||
static int p_set_interval(UINode* node, lua::State* L) {
|
||||
if (dynamic_cast<Container*>(node)) {
|
||||
return lua::pushcfunction(L, lua::wrap<l_container_set_interval>);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int p_get_color(UINode* node, lua_State* L) {
|
||||
static int p_get_color(UINode* node, lua::State* L) {
|
||||
return lua::pushcolor_arr(L, node->getColor());
|
||||
}
|
||||
static int p_get_hover_color(UINode* node, lua_State* L) {
|
||||
static int p_get_hover_color(UINode* node, lua::State* L) {
|
||||
return lua::pushcolor_arr(L, node->getHoverColor());
|
||||
}
|
||||
static int p_get_pressed_color(UINode* node, lua_State* L) {
|
||||
static int p_get_pressed_color(UINode* node, lua::State* L) {
|
||||
return lua::pushcolor_arr(L, node->getPressedColor());
|
||||
}
|
||||
static int p_get_tooltip(UINode* node, lua_State* L) {
|
||||
static int p_get_tooltip(UINode* node, lua::State* L) {
|
||||
return lua::pushwstring(L, node->getTooltip());
|
||||
}
|
||||
static int p_get_tooltip_delay(UINode* node, lua_State* L) {
|
||||
static int p_get_tooltip_delay(UINode* node, lua::State* L) {
|
||||
return lua::pushnumber(L, node->getTooltipDelay());
|
||||
}
|
||||
static int p_get_pos(UINode* node, lua_State* L) {
|
||||
static int p_get_pos(UINode* node, lua::State* L) {
|
||||
return lua::pushvec2_arr(L, node->getPos());
|
||||
}
|
||||
static int p_get_wpos(UINode* node, lua_State* L) {
|
||||
static int p_get_wpos(UINode* node, lua::State* L) {
|
||||
return lua::pushvec2_arr(L, node->calcPos());
|
||||
}
|
||||
static int p_get_size(UINode* node, lua_State* L) {
|
||||
static int p_get_size(UINode* node, lua::State* L) {
|
||||
return lua::pushvec2_arr(L, node->getSize());
|
||||
}
|
||||
static int p_is_interactive(UINode* node, lua_State* L) {
|
||||
static int p_is_interactive(UINode* node, lua::State* L) {
|
||||
return lua::pushboolean(L, node->isInteractive());
|
||||
}
|
||||
static int p_is_visible(UINode* node, lua_State* L) {
|
||||
static int p_is_visible(UINode* node, lua::State* L) {
|
||||
return lua::pushboolean(L, node->isVisible());
|
||||
}
|
||||
static int p_is_enabled(UINode* node, lua_State* L) {
|
||||
static int p_is_enabled(UINode* node, lua::State* L) {
|
||||
return lua::pushboolean(L, node->isEnabled());
|
||||
}
|
||||
static int p_move_into(UINode*, lua_State* L) {
|
||||
static int p_move_into(UINode*, lua::State* L) {
|
||||
return lua::pushcfunction(L, l_move_into);
|
||||
}
|
||||
static int p_get_focused(UINode* node, lua_State* L) {
|
||||
static int p_get_focused(UINode* node, lua::State* L) {
|
||||
return lua::pushboolean(L, node->isFocused());
|
||||
}
|
||||
|
||||
static int l_gui_getattr(lua_State* L) {
|
||||
static int l_gui_getattr(lua::State* L) {
|
||||
auto docname = lua::require_string(L, 1);
|
||||
auto element = lua::require_string(L, 2);
|
||||
auto attr = lua::require_string(L, 3);
|
||||
auto docnode = getDocumentNode(L, docname, element);
|
||||
auto node = docnode.node;
|
||||
|
||||
static const std::unordered_map<std::string_view, std::function<int(UINode*,lua_State*)>> getters {
|
||||
static const std::unordered_map<std::string_view, std::function<int(UINode*,lua::State*)>> getters {
|
||||
{"color", p_get_color},
|
||||
{"hoverColor", p_get_hover_color},
|
||||
{"pressedColor", p_get_pressed_color},
|
||||
@ -371,45 +371,45 @@ static int l_gui_getattr(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void p_set_color(UINode* node, lua_State* L, int idx) {
|
||||
static void p_set_color(UINode* node, lua::State* L, int idx) {
|
||||
node->setColor(lua::tocolor(L, idx));
|
||||
}
|
||||
static void p_set_hover_color(UINode* node, lua_State* L, int idx) {
|
||||
static void p_set_hover_color(UINode* node, lua::State* L, int idx) {
|
||||
node->setHoverColor(lua::tocolor(L, idx));
|
||||
}
|
||||
static void p_set_pressed_color(UINode* node, lua_State* L, int idx) {
|
||||
static void p_set_pressed_color(UINode* node, lua::State* L, int idx) {
|
||||
node->setPressedColor(lua::tocolor(L, idx));
|
||||
}
|
||||
static void p_set_tooltip(UINode* node, lua_State* L, int idx) {
|
||||
static void p_set_tooltip(UINode* node, lua::State* L, int idx) {
|
||||
node->setTooltip(lua::require_wstring(L, idx));
|
||||
}
|
||||
static void p_set_tooltip_delay(UINode* node, lua_State* L, int idx) {
|
||||
static void p_set_tooltip_delay(UINode* node, lua::State* L, int idx) {
|
||||
node->setTooltipDelay(lua::tonumber(L, idx));
|
||||
}
|
||||
static void p_set_pos(UINode* node, lua_State* L, int idx) {
|
||||
static void p_set_pos(UINode* node, lua::State* L, int idx) {
|
||||
node->setPos(lua::tovec2(L, idx));
|
||||
}
|
||||
static void p_set_wpos(UINode* node, lua_State* L, int idx) {
|
||||
static void p_set_wpos(UINode* node, lua::State* L, int idx) {
|
||||
node->setPos(lua::tovec2(L, idx)-node->calcPos());
|
||||
}
|
||||
static void p_set_size(UINode* node, lua_State* L, int idx) {
|
||||
static void p_set_size(UINode* node, lua::State* L, int idx) {
|
||||
node->setSize(lua::tovec2(L, idx));
|
||||
}
|
||||
static void p_set_interactive(UINode* node, lua_State* L, int idx) {
|
||||
static void p_set_interactive(UINode* node, lua::State* L, int idx) {
|
||||
node->setInteractive(lua::toboolean(L, idx));
|
||||
}
|
||||
static void p_set_visible(UINode* node, lua_State* L, int idx) {
|
||||
static void p_set_visible(UINode* node, lua::State* L, int idx) {
|
||||
node->setVisible(lua::toboolean(L, idx));
|
||||
}
|
||||
static void p_set_enabled(UINode* node, lua_State* L, int idx) {
|
||||
static void p_set_enabled(UINode* node, lua::State* L, int idx) {
|
||||
node->setEnabled(lua::toboolean(L, idx));
|
||||
}
|
||||
static void p_set_placeholder(UINode* node, lua_State* L, int idx) {
|
||||
static void p_set_placeholder(UINode* node, lua::State* L, int idx) {
|
||||
if (auto box = dynamic_cast<TextBox*>(node)) {
|
||||
box->setPlaceholder(lua::require_wstring(L, idx));
|
||||
}
|
||||
}
|
||||
static void p_set_text(UINode* node, lua_State* L, int idx) {
|
||||
static void p_set_text(UINode* node, lua::State* L, int idx) {
|
||||
if (auto label = dynamic_cast<Label*>(node)) {
|
||||
label->setText(lua::require_wstring(L, idx));
|
||||
} else if (auto button = dynamic_cast<Button*>(node)) {
|
||||
@ -418,64 +418,64 @@ static void p_set_text(UINode* node, lua_State* L, int idx) {
|
||||
box->setText(lua::require_wstring(L, idx));
|
||||
}
|
||||
}
|
||||
static void p_set_caret(UINode* node, lua_State* L, int idx) {
|
||||
static void p_set_caret(UINode* node, lua::State* L, int idx) {
|
||||
if (auto box = dynamic_cast<TextBox*>(node)) {
|
||||
box->setCaret(static_cast<ptrdiff_t>(lua::tointeger(L, idx)));
|
||||
}
|
||||
}
|
||||
static void p_set_editable(UINode* node, lua_State* L, int idx) {
|
||||
static void p_set_editable(UINode* node, lua::State* L, int idx) {
|
||||
if (auto box = dynamic_cast<TextBox*>(node)) {
|
||||
box->setEditable(lua::toboolean(L, idx));
|
||||
}
|
||||
}
|
||||
static void p_set_src(UINode* node, lua_State* L, int idx) {
|
||||
static void p_set_src(UINode* node, lua::State* L, int idx) {
|
||||
if (auto image = dynamic_cast<Image*>(node)) {
|
||||
image->setTexture(lua::require_string(L, idx));
|
||||
}
|
||||
}
|
||||
static void p_set_value(UINode* node, lua_State* L, int idx) {
|
||||
static void p_set_value(UINode* node, lua::State* L, int idx) {
|
||||
if (auto bar = dynamic_cast<TrackBar*>(node)) {
|
||||
bar->setValue(lua::tonumber(L, idx));
|
||||
}
|
||||
}
|
||||
static void p_set_min(UINode* node, lua_State* L, int idx) {
|
||||
static void p_set_min(UINode* node, lua::State* L, int idx) {
|
||||
if (auto bar = dynamic_cast<TrackBar*>(node)) {
|
||||
bar->setMin(lua::tonumber(L, idx));
|
||||
}
|
||||
}
|
||||
static void p_set_max(UINode* node, lua_State* L, int idx) {
|
||||
static void p_set_max(UINode* node, lua::State* L, int idx) {
|
||||
if (auto bar = dynamic_cast<TrackBar*>(node)) {
|
||||
bar->setMax(lua::tonumber(L, idx));
|
||||
}
|
||||
}
|
||||
static void p_set_step(UINode* node, lua_State* L, int idx) {
|
||||
static void p_set_step(UINode* node, lua::State* L, int idx) {
|
||||
if (auto bar = dynamic_cast<TrackBar*>(node)) {
|
||||
bar->setStep(lua::tonumber(L, idx));
|
||||
}
|
||||
}
|
||||
static void p_set_track_width(UINode* node, lua_State* L, int idx) {
|
||||
static void p_set_track_width(UINode* node, lua::State* L, int idx) {
|
||||
if (auto bar = dynamic_cast<TrackBar*>(node)) {
|
||||
bar->setTrackWidth(lua::tointeger(L, idx));
|
||||
}
|
||||
}
|
||||
static void p_set_track_color(UINode* node, lua_State* L, int idx) {
|
||||
static void p_set_track_color(UINode* node, lua::State* L, int idx) {
|
||||
if (auto bar = dynamic_cast<TrackBar*>(node)) {
|
||||
bar->setTrackColor(lua::tocolor(L, idx));
|
||||
}
|
||||
}
|
||||
static void p_set_checked(UINode* node, lua_State* L, int idx) {
|
||||
static void p_set_checked(UINode* node, lua::State* L, int idx) {
|
||||
if (auto box = dynamic_cast<CheckBox*>(node)) {
|
||||
box->setChecked(lua::toboolean(L, idx));
|
||||
} else if (auto box = dynamic_cast<FullCheckBox*>(node)) {
|
||||
box->setChecked(lua::toboolean(L, idx));
|
||||
}
|
||||
}
|
||||
static void p_set_page(UINode* node, lua_State* L, int idx) {
|
||||
static void p_set_page(UINode* node, lua::State* L, int idx) {
|
||||
if (auto menu = dynamic_cast<Menu*>(node)) {
|
||||
menu->setPage(lua::require_string(L, idx));
|
||||
}
|
||||
}
|
||||
static void p_set_inventory(UINode* node, lua_State* L, int idx) {
|
||||
static void p_set_inventory(UINode* node, lua::State* L, int idx) {
|
||||
if (auto view = dynamic_cast<InventoryView*>(node)) {
|
||||
auto inventory = level->inventories->get(lua::tointeger(L, idx));
|
||||
if (inventory == nullptr) {
|
||||
@ -485,7 +485,7 @@ static void p_set_inventory(UINode* node, lua_State* L, int idx) {
|
||||
}
|
||||
}
|
||||
}
|
||||
static void p_set_focused(const std::shared_ptr<UINode> &node, lua_State* L, int idx) {
|
||||
static void p_set_focused(const std::shared_ptr<UINode> &node, lua::State* L, int idx) {
|
||||
if (lua::toboolean(L, idx) && !node->isFocused()) {
|
||||
engine->getGUI()->setFocus(node);
|
||||
} else if (node->isFocused()){
|
||||
@ -493,7 +493,7 @@ static void p_set_focused(const std::shared_ptr<UINode> &node, lua_State* L, int
|
||||
}
|
||||
}
|
||||
|
||||
static int l_gui_setattr(lua_State* L) {
|
||||
static int l_gui_setattr(lua::State* L) {
|
||||
auto docname = lua::require_string(L, 1);
|
||||
auto element = lua::require_string(L, 2);
|
||||
auto attr = lua::require_string(L, 3);
|
||||
@ -501,7 +501,7 @@ static int l_gui_setattr(lua_State* L) {
|
||||
auto docnode = getDocumentNode(L, docname, element);
|
||||
auto node = docnode.node;
|
||||
|
||||
static const std::unordered_map<std::string_view, std::function<void(UINode*,lua_State*,int)>> setters {
|
||||
static const std::unordered_map<std::string_view, std::function<void(UINode*,lua::State*,int)>> setters {
|
||||
{"color", p_set_color},
|
||||
{"hoverColor", p_set_hover_color},
|
||||
{"pressedColor", p_set_pressed_color},
|
||||
@ -532,7 +532,7 @@ static int l_gui_setattr(lua_State* L) {
|
||||
if (func != setters.end()) {
|
||||
func->second(node.get(), L, 4);
|
||||
}
|
||||
static const std::unordered_map<std::string_view, std::function<void(std::shared_ptr<UINode>,lua_State*,int)>> setters2 {
|
||||
static const std::unordered_map<std::string_view, std::function<void(std::shared_ptr<UINode>,lua::State*,int)>> setters2 {
|
||||
{"focused", p_set_focused},
|
||||
};
|
||||
auto func2 = setters2.find(attr);
|
||||
@ -542,7 +542,7 @@ static int l_gui_setattr(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_gui_get_env(lua_State* L) {
|
||||
static int l_gui_get_env(lua::State* L) {
|
||||
auto name = lua::require_string(L, 1);
|
||||
auto doc = engine->getAssets()->getLayout(name);
|
||||
if (doc == nullptr) {
|
||||
@ -552,7 +552,7 @@ static int l_gui_get_env(lua_State* L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_gui_str(lua_State* L) {
|
||||
static int l_gui_str(lua::State* L) {
|
||||
auto text = lua::require_wstring(L, 1);
|
||||
if (!lua::isnoneornil(L, 2)) {
|
||||
auto context = lua::require_wstring(L, 2);
|
||||
@ -563,7 +563,7 @@ static int l_gui_str(lua_State* L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_gui_reindex(lua_State* L) {
|
||||
static int l_gui_reindex(lua::State* L) {
|
||||
auto name = lua::require_string(L, 1);
|
||||
auto doc = engine->getAssets()->getLayout(name);
|
||||
if (doc == nullptr) {
|
||||
@ -574,7 +574,7 @@ static int l_gui_reindex(lua_State* L) {
|
||||
}
|
||||
|
||||
/// @brief gui.get_locales_info() -> table of tables
|
||||
static int l_gui_get_locales_info(lua_State* L) {
|
||||
static int l_gui_get_locales_info(lua::State* L) {
|
||||
auto& locales = langs::locales_info;
|
||||
lua::createtable(L, 0, locales.size());
|
||||
for (auto& entry : locales) {
|
||||
@ -586,7 +586,7 @@ static int l_gui_get_locales_info(lua_State* L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_gui_getviewport(lua_State* L) {
|
||||
static int l_gui_getviewport(lua::State* L) {
|
||||
return lua::pushvec2_arr(L, engine->getGUI()->getContainer()->getSize());
|
||||
}
|
||||
|
||||
|
||||
@ -23,21 +23,21 @@ namespace scripting {
|
||||
}
|
||||
using namespace scripting;
|
||||
|
||||
static int l_hud_open_inventory(lua_State*) {
|
||||
static int l_hud_open_inventory(lua::State*) {
|
||||
if (!hud->isInventoryOpen()) {
|
||||
hud->openInventory();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_hud_close_inventory(lua_State*) {
|
||||
static int l_hud_close_inventory(lua::State*) {
|
||||
if (hud->isInventoryOpen()) {
|
||||
hud->closeInventory();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_hud_open_block(lua_State* L) {
|
||||
static int l_hud_open_block(lua::State* L) {
|
||||
auto x = lua::tointeger(L, 1);
|
||||
auto y = lua::tointeger(L, 2);
|
||||
auto z = lua::tointeger(L, 3);
|
||||
@ -66,7 +66,7 @@ static int l_hud_open_block(lua_State* L) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
static int l_hud_show_overlay(lua_State* L) {
|
||||
static int l_hud_show_overlay(lua::State* L) {
|
||||
auto name = lua::tostring(L, 1);
|
||||
bool playerInventory = lua::toboolean(L, 2);
|
||||
|
||||
@ -88,29 +88,29 @@ static UiDocument* require_layout(const char* name) {
|
||||
return layout;
|
||||
}
|
||||
|
||||
static int l_hud_open_permanent(lua_State* L) {
|
||||
static int l_hud_open_permanent(lua::State* L) {
|
||||
auto layout = require_layout(lua::tostring(L, 1));
|
||||
hud->openPermanent(layout);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_hud_close(lua_State* L) {
|
||||
static int l_hud_close(lua::State* L) {
|
||||
auto layout = require_layout(lua::tostring(L, 1));
|
||||
hud->remove(layout->getRoot());
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_hud_pause(lua_State*) {
|
||||
static int l_hud_pause(lua::State*) {
|
||||
hud->setPause(true);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_hud_resume(lua_State*) {
|
||||
static int l_hud_resume(lua::State*) {
|
||||
hud->setPause(false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_hud_get_block_inventory(lua_State* L) {
|
||||
static int l_hud_get_block_inventory(lua::State* L) {
|
||||
auto inventory = hud->getBlockInventory();
|
||||
if (inventory == nullptr) {
|
||||
return lua::pushinteger(L, 0);
|
||||
@ -119,7 +119,7 @@ static int l_hud_get_block_inventory(lua_State* L) {
|
||||
}
|
||||
}
|
||||
|
||||
static int l_hud_get_player(lua_State* L) {
|
||||
static int l_hud_get_player(lua::State* L) {
|
||||
auto player = hud->getPlayer();
|
||||
return lua::pushinteger(L, player->getId());
|
||||
}
|
||||
|
||||
@ -13,17 +13,17 @@ namespace scripting {
|
||||
}
|
||||
using namespace scripting;
|
||||
|
||||
static int l_keycode(lua_State* L) {
|
||||
static int l_keycode(lua::State* L) {
|
||||
auto name = lua::require_string(L, 1);
|
||||
return lua::pushinteger(L, static_cast<int>(input_util::keycode_from(name)));
|
||||
}
|
||||
|
||||
static int l_mousecode(lua_State* L) {
|
||||
static int l_mousecode(lua::State* L) {
|
||||
auto name = lua::require_string(L, 1);
|
||||
return lua::pushinteger(L, static_cast<int>(input_util::mousecode_from(name)));
|
||||
}
|
||||
|
||||
static int l_add_callback(lua_State* L) {
|
||||
static int l_add_callback(lua::State* L) {
|
||||
auto bindname = lua::require_string(L, 1);
|
||||
const auto& bind = Events::bindings.find(bindname);
|
||||
if (bind == Events::bindings.end()) {
|
||||
@ -44,11 +44,11 @@ static int l_add_callback(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_get_mouse_pos(lua_State* L) {
|
||||
static int l_get_mouse_pos(lua::State* L) {
|
||||
return lua::pushvec2_arr(L, Events::cursor);
|
||||
}
|
||||
|
||||
static int l_get_bindings(lua_State* L) {
|
||||
static int l_get_bindings(lua::State* L) {
|
||||
auto& bindings = Events::bindings;
|
||||
lua::createtable(L, bindings.size(), 0);
|
||||
|
||||
|
||||
@ -37,7 +37,7 @@ static void validate_slotid(int slotid, Inventory* inv) {
|
||||
}
|
||||
}
|
||||
|
||||
static int l_inventory_get(lua_State* L) {
|
||||
static int l_inventory_get(lua::State* L) {
|
||||
auto invid = lua::tointeger(L, 1);
|
||||
auto slotid = lua::tointeger(L, 2);
|
||||
auto inv = get_inventory(invid);
|
||||
@ -48,7 +48,7 @@ static int l_inventory_get(lua_State* L) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
static int l_inventory_set(lua_State* L) {
|
||||
static int l_inventory_set(lua::State* L) {
|
||||
auto invid = lua::tointeger(L, 1);
|
||||
auto slotid = lua::tointeger(L, 2);
|
||||
auto itemid = lua::tointeger(L, 3);
|
||||
@ -63,13 +63,13 @@ static int l_inventory_set(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_inventory_size(lua_State* L) {
|
||||
static int l_inventory_size(lua::State* L) {
|
||||
auto invid = lua::tointeger(L, 1);
|
||||
auto inv = get_inventory(invid);
|
||||
return lua::pushinteger(L, inv->size());
|
||||
}
|
||||
|
||||
static int l_inventory_add(lua_State* L) {
|
||||
static int l_inventory_add(lua::State* L) {
|
||||
auto invid = lua::tointeger(L, 1);
|
||||
auto itemid = lua::tointeger(L, 2);
|
||||
auto count = lua::tointeger(L, 3);
|
||||
@ -81,7 +81,7 @@ static int l_inventory_add(lua_State* L) {
|
||||
return lua::pushinteger(L, item.getCount());
|
||||
}
|
||||
|
||||
static int l_inventory_get_block(lua_State* L) {
|
||||
static int l_inventory_get_block(lua::State* L) {
|
||||
auto x = lua::tointeger(L, 1);
|
||||
auto y = lua::tointeger(L, 2);
|
||||
auto z = lua::tointeger(L, 3);
|
||||
@ -89,7 +89,7 @@ static int l_inventory_get_block(lua_State* L) {
|
||||
return lua::pushinteger(L, id);
|
||||
}
|
||||
|
||||
static int l_inventory_bind_block(lua_State* L) {
|
||||
static int l_inventory_bind_block(lua::State* L) {
|
||||
auto id = lua::tointeger(L, 1);
|
||||
auto x = lua::tointeger(L, 2);
|
||||
auto y = lua::tointeger(L, 3);
|
||||
@ -98,7 +98,7 @@ static int l_inventory_bind_block(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_inventory_unbind_block(lua_State* L) {
|
||||
static int l_inventory_unbind_block(lua::State* L) {
|
||||
auto x = lua::tointeger(L, 1);
|
||||
auto y = lua::tointeger(L, 2);
|
||||
auto z = lua::tointeger(L, 3);
|
||||
@ -106,7 +106,7 @@ static int l_inventory_unbind_block(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_inventory_clone(lua_State* L) {
|
||||
static int l_inventory_clone(lua::State* L) {
|
||||
auto id = lua::tointeger(L, 1);
|
||||
auto clone = level->inventories->clone(id);
|
||||
if (clone == nullptr) {
|
||||
@ -115,7 +115,7 @@ static int l_inventory_clone(lua_State* L) {
|
||||
return lua::pushinteger(L, clone->getId());
|
||||
}
|
||||
|
||||
static int l_inventory_move(lua_State* L) {
|
||||
static int l_inventory_move(lua::State* L) {
|
||||
auto invAid = lua::tointeger(L, 1);
|
||||
auto slotAid = lua::tointeger(L, 2);
|
||||
auto invA = get_inventory(invAid, 1);
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
|
||||
using namespace scripting;
|
||||
|
||||
static int l_item_name(lua_State* L) {
|
||||
static int l_item_name(lua::State* L) {
|
||||
auto indices = content->getIndices();
|
||||
auto id = lua::tointeger(L, 1);
|
||||
if (static_cast<size_t>(id) >= indices->countItemDefs()) {
|
||||
@ -15,12 +15,12 @@ static int l_item_name(lua_State* L) {
|
||||
return lua::pushstring(L, def->name);
|
||||
}
|
||||
|
||||
static int l_item_index(lua_State* L) {
|
||||
static int l_item_index(lua::State* L) {
|
||||
auto name = lua::require_string(L, 1);
|
||||
return lua::pushinteger(L, content->requireItem(name).rt.id);
|
||||
}
|
||||
|
||||
static int l_item_stack_size(lua_State* L) {
|
||||
static int l_item_stack_size(lua::State* L) {
|
||||
auto indices = content->getIndices();
|
||||
auto id = lua::tointeger(L, 1);
|
||||
if (static_cast<size_t>(id) >= indices->countItemDefs()) {
|
||||
@ -30,7 +30,7 @@ static int l_item_stack_size(lua_State* L) {
|
||||
return lua::pushinteger(L, def->stackSize);
|
||||
}
|
||||
|
||||
static int l_item_defs_count(lua_State* L) {
|
||||
static int l_item_defs_count(lua::State* L) {
|
||||
return lua::pushinteger(L, indices->countItemDefs());
|
||||
}
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
#include "../../../coders/json.hpp"
|
||||
#include "../../../data/dynamic.hpp"
|
||||
|
||||
static int l_json_stringify(lua_State* L) {
|
||||
static int l_json_stringify(lua::State* L) {
|
||||
auto value = lua::tovalue(L, 1);
|
||||
|
||||
if (auto mapptr = std::get_if<dynamic::Map_sptr>(&value)) {
|
||||
@ -15,7 +15,7 @@ static int l_json_stringify(lua_State* L) {
|
||||
}
|
||||
}
|
||||
|
||||
static int l_json_parse(lua_State* L) {
|
||||
static int l_json_parse(lua::State* L) {
|
||||
auto string = lua::require_string(L, 1);
|
||||
auto element = json::parse("<string>", string);
|
||||
return lua::pushvalue(L, element);
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
|
||||
using namespace scripting;
|
||||
|
||||
static int l_pack_get_folder(lua_State* L) {
|
||||
static int l_pack_get_folder(lua::State* L) {
|
||||
std::string packName = lua::tostring(L, 1);
|
||||
if (packName == "core") {
|
||||
auto folder = engine->getPaths()->getResources().u8string()+"/";
|
||||
@ -29,7 +29,7 @@ static int l_pack_get_folder(lua_State* L) {
|
||||
}
|
||||
|
||||
/// @brief pack.get_installed() -> array<string>
|
||||
static int l_pack_get_installed(lua_State* L) {
|
||||
static int l_pack_get_installed(lua::State* L) {
|
||||
auto& packs = engine->getContentPacks();
|
||||
lua::createtable(L, packs.size(), 0);
|
||||
for (size_t i = 0; i < packs.size(); i++) {
|
||||
@ -40,7 +40,7 @@ static int l_pack_get_installed(lua_State* L) {
|
||||
}
|
||||
|
||||
/// @brief pack.get_available() -> array<string>
|
||||
static int l_pack_get_available(lua_State* L) {
|
||||
static int l_pack_get_available(lua::State* L) {
|
||||
fs::path worldFolder("");
|
||||
if (level) {
|
||||
worldFolder = level->getWorld()->wfile->getFolder();
|
||||
@ -62,7 +62,7 @@ static int l_pack_get_available(lua_State* L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_pack_get_info(lua_State* L, const ContentPack& pack, const Content* content) {
|
||||
static int l_pack_get_info(lua::State* L, const ContentPack& pack, const Content* content) {
|
||||
lua::createtable(L, 0, 5);
|
||||
|
||||
lua::pushstring(L, pack.id);
|
||||
@ -123,7 +123,7 @@ static int l_pack_get_info(lua_State* L, const ContentPack& pack, const Content*
|
||||
/// version: str,
|
||||
/// [optional] has_indices: bool
|
||||
/// } or nil
|
||||
static int l_pack_get_info(lua_State* L) {
|
||||
static int l_pack_get_info(lua::State* L) {
|
||||
auto packid = lua::tostring(L, 1);
|
||||
|
||||
auto content = engine->getContent();
|
||||
@ -149,7 +149,7 @@ static int l_pack_get_info(lua_State* L) {
|
||||
return l_pack_get_info(L, pack, content);
|
||||
}
|
||||
|
||||
static int l_pack_get_base_packs(lua_State* L) {
|
||||
static int l_pack_get_base_packs(lua::State* L) {
|
||||
auto& packs = engine->getBasePacks();
|
||||
lua::createtable(L, packs.size(), 0);
|
||||
for (size_t i = 0; i < packs.size(); i++) {
|
||||
|
||||
@ -10,18 +10,18 @@
|
||||
|
||||
using namespace scripting;
|
||||
|
||||
inline std::shared_ptr<Player> get_player(lua_State* L, int idx) {
|
||||
inline std::shared_ptr<Player> get_player(lua::State* L, int idx) {
|
||||
return level->getObject<Player>(lua::tointeger(L, idx));
|
||||
}
|
||||
|
||||
static int l_player_get_pos(lua_State* L) {
|
||||
static int l_player_get_pos(lua::State* L) {
|
||||
if (auto player = get_player(L, 1)) {
|
||||
return lua::pushvec3(L, player->hitbox->position);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_player_set_pos(lua_State* L) {
|
||||
static int l_player_set_pos(lua::State* L) {
|
||||
auto player = get_player(L, 1);
|
||||
if (!player) {
|
||||
return 0;
|
||||
@ -33,14 +33,14 @@ static int l_player_set_pos(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_player_get_vel(lua_State* L) {
|
||||
static int l_player_get_vel(lua::State* L) {
|
||||
if (auto player = get_player(L, 1)) {
|
||||
return lua::pushvec3(L, player->hitbox->velocity);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_player_set_vel(lua_State* L) {
|
||||
static int l_player_set_vel(lua::State* L) {
|
||||
auto player = get_player(L, 1);
|
||||
if (!player) {
|
||||
return 0;
|
||||
@ -52,23 +52,23 @@ static int l_player_set_vel(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_player_get_rot(lua_State* L) {
|
||||
static int l_player_get_rot(lua::State* L) {
|
||||
if (auto player = get_player(L, 1)) {
|
||||
return lua::pushvec3(L, player->cam);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_player_set_rot(lua_State* L) {
|
||||
static int l_player_set_rot(lua::State* L) {
|
||||
auto player = get_player(L, 1);
|
||||
if (!player) {
|
||||
return 0;
|
||||
}
|
||||
glm::vec3& cam = player->cam;
|
||||
|
||||
lua_Number x = lua::tonumber(L, 2);
|
||||
lua_Number y = lua::tonumber(L, 3);
|
||||
lua_Number z = cam.z;
|
||||
auto x = lua::tonumber(L, 2);
|
||||
auto y = lua::tonumber(L, 3);
|
||||
auto z = cam.z;
|
||||
if (lua::isnumber(L, 4)) {
|
||||
z = lua::tonumber(L, 4);
|
||||
}
|
||||
@ -78,7 +78,7 @@ static int l_player_set_rot(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_player_get_inv(lua_State* L) {
|
||||
static int l_player_get_inv(lua::State* L) {
|
||||
auto player = get_player(L, 1);
|
||||
if (!player) {
|
||||
return 0;
|
||||
@ -88,35 +88,35 @@ static int l_player_get_inv(lua_State* L) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
static int l_player_is_flight(lua_State* L) {
|
||||
static int l_player_is_flight(lua::State* L) {
|
||||
if (auto player = get_player(L, 1)) {
|
||||
return lua::pushboolean(L, player->isFlight());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_player_set_flight(lua_State* L) {
|
||||
static int l_player_set_flight(lua::State* L) {
|
||||
if (auto player = get_player(L, 1)) {
|
||||
player->setFlight(lua::toboolean(L, 2));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_player_is_noclip(lua_State* L) {
|
||||
static int l_player_is_noclip(lua::State* L) {
|
||||
if (auto player = get_player(L, 1)) {
|
||||
return lua::pushboolean(L, player->isNoclip());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_player_set_noclip(lua_State* L) {
|
||||
static int l_player_set_noclip(lua::State* L) {
|
||||
if (auto player = get_player(L, 1)) {
|
||||
player->setNoclip(lua::toboolean(L, 2));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_player_get_selected_block(lua_State* L) {
|
||||
static int l_player_get_selected_block(lua::State* L) {
|
||||
if (auto player = get_player(L, 1)) {
|
||||
if (player->selection.vox.id == BLOCK_VOID) {
|
||||
return 0;
|
||||
|
||||
@ -3,11 +3,11 @@
|
||||
#include "../../../engine.hpp"
|
||||
#include "../../../window/Window.hpp"
|
||||
|
||||
static int l_time_uptime(lua_State* L) {
|
||||
static int l_time_uptime(lua::State* L) {
|
||||
return lua::pushnumber(L, Window::time());
|
||||
}
|
||||
|
||||
static int l_time_delta(lua_State* L) {
|
||||
static int l_time_delta(lua::State* L) {
|
||||
return lua::pushnumber(L, scripting::engine->getDelta());
|
||||
}
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
|
||||
using namespace scripting;
|
||||
|
||||
static int l_toml_stringify(lua_State* L) {
|
||||
static int l_toml_stringify(lua::State* L) {
|
||||
auto value = lua::tovalue(L, 1);
|
||||
|
||||
if (auto mapptr = std::get_if<dynamic::Map_sptr>(&value)) {
|
||||
@ -16,7 +16,7 @@ static int l_toml_stringify(lua_State* L) {
|
||||
}
|
||||
}
|
||||
|
||||
static int l_toml_parse(lua_State* L) {
|
||||
static int l_toml_parse(lua::State* L) {
|
||||
auto string = lua::require_string(L, 1);
|
||||
auto element = toml::parse("<string>", string);
|
||||
auto value = std::make_unique<dynamic::Value>(element);
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
using namespace scripting;
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
static int l_world_get_list(lua_State* L) {
|
||||
static int l_world_get_list(lua::State* L) {
|
||||
auto paths = engine->getPaths();
|
||||
auto worlds = paths->scanForWorlds();
|
||||
|
||||
@ -40,25 +40,25 @@ static int l_world_get_list(lua_State* L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_world_get_total_time(lua_State* L) {
|
||||
static int l_world_get_total_time(lua::State* L) {
|
||||
return lua::pushnumber(L, level->getWorld()->totalTime);
|
||||
}
|
||||
|
||||
static int l_world_get_day_time(lua_State* L) {
|
||||
static int l_world_get_day_time(lua::State* L) {
|
||||
return lua::pushnumber(L, level->getWorld()->daytime);
|
||||
}
|
||||
|
||||
static int l_world_set_day_time(lua_State* L) {
|
||||
static int l_world_set_day_time(lua::State* L) {
|
||||
auto value = lua::tonumber(L, 1);
|
||||
level->getWorld()->daytime = fmod(value, 1.0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_world_get_seed(lua_State* L) {
|
||||
static int l_world_get_seed(lua::State* L) {
|
||||
return lua::pushinteger(L, level->getWorld()->getSeed());
|
||||
}
|
||||
|
||||
static int l_world_exists(lua_State* L) {
|
||||
static int l_world_exists(lua::State* L) {
|
||||
auto name = lua::require_string(L, 1);
|
||||
auto worldsDir = engine->getPaths()->getWorldFolder(name);
|
||||
return lua::pushboolean(L, fs::is_directory(worldsDir));
|
||||
|
||||
@ -26,6 +26,10 @@ namespace lua {
|
||||
};
|
||||
|
||||
void log_error(const std::string& text);
|
||||
|
||||
using State = lua_State;
|
||||
using Number = lua_Number;
|
||||
using Integer = lua_Integer;
|
||||
}
|
||||
|
||||
#endif // LOGIC_SCRIPTING_LUA_HPP_
|
||||
|
||||
@ -8,14 +8,14 @@
|
||||
#include <iostream>
|
||||
|
||||
static debug::Logger logger("lua-state");
|
||||
static lua_State* main_thread = nullptr;
|
||||
static lua::State* main_thread = nullptr;
|
||||
|
||||
using namespace lua;
|
||||
|
||||
luaerror::luaerror(const std::string& message) : std::runtime_error(message) {
|
||||
}
|
||||
|
||||
static void remove_lib_funcs(lua_State* L, const char* libname, const char* funcs[]) {
|
||||
static void remove_lib_funcs(lua::State* L, const char* libname, const char* funcs[]) {
|
||||
if (getglobal(L, libname)) {
|
||||
for (uint i = 0; funcs[i]; i++) {
|
||||
pushnil(L);
|
||||
@ -24,7 +24,7 @@ static void remove_lib_funcs(lua_State* L, const char* libname, const char* func
|
||||
}
|
||||
}
|
||||
|
||||
static void create_libs(lua_State* L) {
|
||||
static void create_libs(lua::State* L) {
|
||||
openlib(L, "audio", audiolib);
|
||||
openlib(L, "block", blocklib);
|
||||
openlib(L, "console", consolelib);
|
||||
@ -86,7 +86,7 @@ void lua::finalize() {
|
||||
lua_close(main_thread);
|
||||
}
|
||||
|
||||
bool lua::emit_event(lua_State* L, const std::string &name, std::function<int(lua_State*)> args) {
|
||||
bool lua::emit_event(lua::State* L, const std::string &name, std::function<int(lua::State*)> args) {
|
||||
getglobal(L, "events");
|
||||
getfield(L, "emit");
|
||||
pushstring(L, name);
|
||||
@ -96,6 +96,6 @@ bool lua::emit_event(lua_State* L, const std::string &name, std::function<int(lu
|
||||
return result;
|
||||
}
|
||||
|
||||
lua_State* lua::get_main_thread() {
|
||||
lua::State* lua::get_main_thread() {
|
||||
return main_thread;
|
||||
}
|
||||
|
||||
@ -14,8 +14,8 @@ namespace lua {
|
||||
void initialize();
|
||||
void finalize();
|
||||
|
||||
bool emit_event(lua_State*, const std::string& name, std::function<int(lua_State*)> args=[](auto*){return 0;});
|
||||
lua_State* get_main_thread();
|
||||
bool emit_event(lua::State*, const std::string& name, std::function<int(lua::State*)> args=[](auto*){return 0;});
|
||||
lua::State* get_main_thread();
|
||||
}
|
||||
|
||||
#endif // LOGIC_SCRIPTING_LUA_STATE_HPP_
|
||||
|
||||
@ -3,8 +3,8 @@
|
||||
#include <iostream>
|
||||
|
||||
/// @brief Modified version of luaB_print from lbaselib.c
|
||||
int l_print(lua_State* L) {
|
||||
int n = lua_gettop(L); /* number of arguments */
|
||||
int l_print(lua::State* L) {
|
||||
int n = lua::gettop(L); /* number of arguments */
|
||||
lua::getglobal(L, "tostring");
|
||||
for (int i=1; i<=n; i++) {
|
||||
lua::pushvalue(L, -1); /* function to be called */
|
||||
|
||||
@ -13,7 +13,7 @@ std::string lua::env_name(int env) {
|
||||
return "_ENV"+util::mangleid(env);
|
||||
}
|
||||
|
||||
int lua::pushvalue(lua_State* L, const dynamic::Value& value) {
|
||||
int lua::pushvalue(State* L, const dynamic::Value& value) {
|
||||
using namespace dynamic;
|
||||
|
||||
if (auto* flag = std::get_if<bool>(&value)) {
|
||||
@ -44,15 +44,15 @@ int lua::pushvalue(lua_State* L, const dynamic::Value& value) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::wstring lua::require_wstring(lua_State* L, int idx) {
|
||||
return util::str2wstr_utf8(lua::require_string(L, idx));
|
||||
std::wstring lua::require_wstring(State* L, int idx) {
|
||||
return util::str2wstr_utf8(require_string(L, idx));
|
||||
}
|
||||
|
||||
int lua::pushwstring(lua_State* L, const std::wstring& str) {
|
||||
return lua::pushstring(L, util::wstr2str_utf8(str));
|
||||
int lua::pushwstring(State* L, const std::wstring& str) {
|
||||
return pushstring(L, util::wstr2str_utf8(str));
|
||||
}
|
||||
|
||||
dynamic::Value lua::tovalue(lua_State* L, int idx) {
|
||||
dynamic::Value lua::tovalue(State* L, int idx) {
|
||||
using namespace dynamic;
|
||||
auto type = lua::type(L, idx);
|
||||
switch (type) {
|
||||
@ -64,7 +64,7 @@ dynamic::Value lua::tovalue(lua_State* L, int idx) {
|
||||
case LUA_TNUMBER: {
|
||||
auto number = tonumber(L, idx);
|
||||
auto integer = tointeger(L, idx);
|
||||
if (number == static_cast<lua_Number>(integer)) {
|
||||
if (number == static_cast<Number>(integer)) {
|
||||
return integer;
|
||||
} else {
|
||||
return number;
|
||||
@ -73,7 +73,7 @@ dynamic::Value lua::tovalue(lua_State* L, int idx) {
|
||||
case LUA_TSTRING:
|
||||
return std::string(tostring(L, idx));
|
||||
case LUA_TTABLE: {
|
||||
int len = lua::objlen(L, idx);
|
||||
int len = objlen(L, idx);
|
||||
if (len) {
|
||||
// array
|
||||
auto list = create_list();
|
||||
@ -88,7 +88,7 @@ dynamic::Value lua::tovalue(lua_State* L, int idx) {
|
||||
auto map = create_map();
|
||||
pushvalue(L, idx);
|
||||
pushnil(L);
|
||||
while (lua_next(L, -2)) {
|
||||
while (next(L, -2)) {
|
||||
pushvalue(L, -2);
|
||||
auto key = tostring(L, -1);
|
||||
map->put(key, tovalue(L, -2));
|
||||
@ -105,14 +105,14 @@ dynamic::Value lua::tovalue(lua_State* L, int idx) {
|
||||
}
|
||||
}
|
||||
|
||||
int lua::call(lua_State* L, int argc, int nresults) {
|
||||
int lua::call(State* L, int argc, int nresults) {
|
||||
if (lua_pcall(L, argc, nresults, 0)) {
|
||||
throw luaerror(tostring(L, -1));
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int lua::call_nothrow(lua_State* L, int argc) {
|
||||
int lua::call_nothrow(State* L, int argc) {
|
||||
if (lua_pcall(L, argc, LUA_MULTRET, 0)) {
|
||||
log_error(tostring(L, -1));
|
||||
return 0;
|
||||
@ -120,7 +120,7 @@ int lua::call_nothrow(lua_State* L, int argc) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
void lua::dump_stack(lua_State* L) {
|
||||
void lua::dump_stack(State* L) {
|
||||
int top = gettop(L);
|
||||
for (int i = 1; i <= top; i++) {
|
||||
std::cout << std::setw(3) << i << std::setw(20) << luaL_typename(L, i) << std::setw(30);
|
||||
@ -145,7 +145,7 @@ void lua::dump_stack(lua_State* L) {
|
||||
}
|
||||
}
|
||||
|
||||
static std::shared_ptr<std::string> createLambdaHandler(lua_State* L) {
|
||||
static std::shared_ptr<std::string> createLambdaHandler(State* L) {
|
||||
auto ptr = reinterpret_cast<ptrdiff_t>(topointer(L, -1));
|
||||
auto name = util::mangleid(ptr);
|
||||
getglobal(L, LAMBDAS_TABLE);
|
||||
@ -162,16 +162,16 @@ static std::shared_ptr<std::string> createLambdaHandler(lua_State* L) {
|
||||
});
|
||||
}
|
||||
|
||||
runnable lua::create_runnable(lua_State* L) {
|
||||
runnable lua::create_runnable(State* L) {
|
||||
auto funcptr = createLambdaHandler(L);
|
||||
return [=]() {
|
||||
lua_getglobal(L, LAMBDAS_TABLE.c_str());
|
||||
lua_getfield(L, -1, funcptr->c_str());
|
||||
getglobal(L, LAMBDAS_TABLE);
|
||||
getfield(L, *funcptr);
|
||||
call_nothrow(L, 0);
|
||||
};
|
||||
}
|
||||
|
||||
scripting::common_func lua::create_lambda(lua_State* L) {
|
||||
scripting::common_func lua::create_lambda(State* L) {
|
||||
auto funcptr = createLambdaHandler(L);
|
||||
return [=](const std::vector<dynamic::Value>& args) {
|
||||
getglobal(L, LAMBDAS_TABLE);
|
||||
@ -188,7 +188,7 @@ scripting::common_func lua::create_lambda(lua_State* L) {
|
||||
};
|
||||
}
|
||||
|
||||
int lua::createEnvironment(lua_State* L, int parent) {
|
||||
int lua::createEnvironment(State* L, int parent) {
|
||||
int id = nextEnvironment++;
|
||||
|
||||
// local env = {}
|
||||
@ -204,7 +204,7 @@ int lua::createEnvironment(lua_State* L, int parent) {
|
||||
}
|
||||
}
|
||||
setfield(L, "__index");
|
||||
lua_setmetatable(L, -2);
|
||||
setmetatable(L);
|
||||
|
||||
// envname = env
|
||||
setglobal(L, env_name(id));
|
||||
@ -212,7 +212,7 @@ int lua::createEnvironment(lua_State* L, int parent) {
|
||||
}
|
||||
|
||||
|
||||
void lua::removeEnvironment(lua_State* L, int id) {
|
||||
void lua::removeEnvironment(State* L, int id) {
|
||||
if (id == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -24,39 +24,42 @@ namespace lua {
|
||||
return result;
|
||||
}
|
||||
|
||||
inline void pop(lua_State* L, int n=1) {
|
||||
inline void pop(lua::State* L, int n=1) {
|
||||
lua_pop(L, n);
|
||||
}
|
||||
inline int gettop(lua_State* L) {
|
||||
inline int gettop(lua::State* L) {
|
||||
return lua_gettop(L);
|
||||
}
|
||||
inline size_t objlen(lua_State* L, int idx) {
|
||||
inline size_t objlen(lua::State* L, int idx) {
|
||||
return lua_objlen(L, idx);
|
||||
}
|
||||
inline int type(lua_State* L, int idx) {
|
||||
inline int next(lua::State* L, int idx) {
|
||||
return lua_next(L, idx);
|
||||
}
|
||||
inline int type(lua::State* L, int idx) {
|
||||
return lua_type(L, idx);
|
||||
}
|
||||
inline const char* type_name(lua_State* L, int idx) {
|
||||
inline const char* type_name(lua::State* L, int idx) {
|
||||
return lua_typename(L, idx);
|
||||
}
|
||||
inline int rawgeti(lua_State* L, int n, int idx=-1) {
|
||||
inline int rawgeti(lua::State* L, int n, int idx=-1) {
|
||||
lua_rawgeti(L, idx, n);
|
||||
return 1;
|
||||
}
|
||||
inline void rawseti(lua_State* L, int n, int idx=-2) {
|
||||
inline void rawseti(lua::State* L, int n, int idx=-2) {
|
||||
lua_rawseti(L, idx, n);
|
||||
}
|
||||
|
||||
inline int createtable(lua_State* L, int narr, int nrec) {
|
||||
inline int createtable(lua::State* L, int narr, int nrec) {
|
||||
lua_createtable(L, narr, nrec);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline bool isnil(lua_State* L, int idx) {
|
||||
inline bool isnil(lua::State* L, int idx) {
|
||||
return lua_isnil(L, idx);
|
||||
}
|
||||
|
||||
inline bool getglobal(lua_State* L, const std::string& name) {
|
||||
inline bool getglobal(lua::State* L, const std::string& name) {
|
||||
lua_getglobal(L, name.c_str());
|
||||
if (isnil(L, -1)) {
|
||||
pop(L);
|
||||
@ -65,7 +68,7 @@ namespace lua {
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool hasglobal(lua_State* L, const std::string& name) {
|
||||
inline bool hasglobal(lua::State* L, const std::string& name) {
|
||||
lua_getglobal(L, name.c_str());
|
||||
if (isnil(L, -1)) {
|
||||
pop(L);
|
||||
@ -77,43 +80,43 @@ namespace lua {
|
||||
|
||||
// function wrappers with number of pushed values as return value
|
||||
|
||||
inline int pushnil(lua_State* L) {
|
||||
inline int pushnil(lua::State* L) {
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int pushinteger(lua_State* L, lua_Integer x) {
|
||||
inline int pushinteger(lua::State* L, lua::Integer x) {
|
||||
lua_pushinteger(L, x);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int pushnumber(lua_State* L, lua_Number x) {
|
||||
inline int pushnumber(lua::State* L, lua::Number x) {
|
||||
lua_pushnumber(L, x);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int pushivec3(lua_State* L, lua_Integer x, lua_Integer y, lua_Integer z) {
|
||||
inline int pushivec3(lua::State* L, lua::Integer x, lua::Integer y, lua::Integer z) {
|
||||
pushinteger(L, x);
|
||||
pushinteger(L, y);
|
||||
pushinteger(L, z);
|
||||
return 3;
|
||||
}
|
||||
|
||||
inline int pushivec3(lua_State* L, glm::ivec3 vec) {
|
||||
inline int pushivec3(lua::State* L, glm::ivec3 vec) {
|
||||
pushinteger(L, vec.x);
|
||||
pushinteger(L, vec.y);
|
||||
pushinteger(L, vec.z);
|
||||
return 3;
|
||||
}
|
||||
|
||||
inline int pushvec3(lua_State* L, glm::vec3 vec) {
|
||||
inline int pushvec3(lua::State* L, glm::vec3 vec) {
|
||||
pushnumber(L, vec.x);
|
||||
pushnumber(L, vec.y);
|
||||
pushnumber(L, vec.z);
|
||||
return 3;
|
||||
}
|
||||
|
||||
inline int pushvec4(lua_State* L, glm::vec4 vec) {
|
||||
inline int pushvec4(lua::State* L, glm::vec4 vec) {
|
||||
pushnumber(L, vec.x);
|
||||
pushnumber(L, vec.y);
|
||||
pushnumber(L, vec.z);
|
||||
@ -121,10 +124,14 @@ namespace lua {
|
||||
return 4;
|
||||
}
|
||||
|
||||
inline int pushvec2_arr(lua_State* L, glm::vec2 vec) {
|
||||
inline void setmetatable(lua::State* L, int idx=-2) {
|
||||
lua_setmetatable(L, idx);
|
||||
}
|
||||
|
||||
inline int pushvec2_arr(lua::State* L, glm::vec2 vec) {
|
||||
createtable(L, 2, 0);
|
||||
getglobal(L, "vec2_mt");
|
||||
lua_setmetatable(L, -2);
|
||||
setmetatable(L);
|
||||
|
||||
pushnumber(L, vec.x);
|
||||
rawseti(L, 1);
|
||||
@ -133,10 +140,10 @@ namespace lua {
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int pushvec3_arr(lua_State* L, glm::vec3 vec) {
|
||||
inline int pushvec3_arr(lua::State* L, glm::vec3 vec) {
|
||||
createtable(L, 3, 0);
|
||||
getglobal(L, "vec3_mt");
|
||||
lua_setmetatable(L, -2);
|
||||
setmetatable(L);
|
||||
|
||||
pushnumber(L, vec.x);
|
||||
rawseti(L, 1);
|
||||
@ -147,10 +154,10 @@ namespace lua {
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int pushvec4_arr(lua_State* L, glm::vec4 vec) {
|
||||
inline int pushvec4_arr(lua::State* L, glm::vec4 vec) {
|
||||
createtable(L, 4, 0);
|
||||
getglobal(L, "vec4_mt");
|
||||
lua_setmetatable(L, -2);
|
||||
setmetatable(L);
|
||||
|
||||
pushnumber(L, vec.x);
|
||||
rawseti(L, 1);
|
||||
@ -162,10 +169,10 @@ namespace lua {
|
||||
rawseti(L, 4);
|
||||
return 1;
|
||||
}
|
||||
inline int pushcolor_arr(lua_State* L, glm::vec4 vec) {
|
||||
inline int pushcolor_arr(lua::State* L, glm::vec4 vec) {
|
||||
createtable(L, 4, 0);
|
||||
getglobal(L, "color_mt");
|
||||
lua_setmetatable(L, -2);
|
||||
setmetatable(L);
|
||||
|
||||
pushinteger(L, vec.x*255);
|
||||
rawseti(L, 1);
|
||||
@ -177,11 +184,11 @@ namespace lua {
|
||||
rawseti(L, 4);
|
||||
return 1;
|
||||
}
|
||||
inline int pushcfunction(lua_State* L, lua_CFunction func) {
|
||||
inline int pushcfunction(lua::State* L, lua_CFunction func) {
|
||||
lua_pushcfunction(L, func);
|
||||
return 1;
|
||||
}
|
||||
inline int pushstring(lua_State* L, const std::string& str) {
|
||||
inline int pushstring(lua::State* L, const std::string& str) {
|
||||
lua_pushstring(L, str.c_str());
|
||||
return 1;
|
||||
}
|
||||
@ -192,53 +199,53 @@ namespace lua {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int pushwstring(lua_State* L, const std::wstring& str);
|
||||
int pushwstring(lua::State* L, const std::wstring& str);
|
||||
|
||||
inline int pushboolean(lua_State* L, bool value) {
|
||||
inline int pushboolean(lua::State* L, bool value) {
|
||||
lua_pushboolean(L, value);
|
||||
return 1;
|
||||
}
|
||||
inline int pushvalue(lua_State* L, int idx) {
|
||||
inline int pushvalue(lua::State* L, int idx) {
|
||||
lua_pushvalue(L, idx);
|
||||
return 1;
|
||||
}
|
||||
inline int pushglobals(lua_State* L) {
|
||||
inline int pushglobals(lua::State* L) {
|
||||
return pushvalue(L, LUA_GLOBALSINDEX);
|
||||
}
|
||||
inline bool isnoneornil(lua_State* L, int idx) {
|
||||
inline bool isnoneornil(lua::State* L, int idx) {
|
||||
return lua_isnoneornil(L, idx);
|
||||
}
|
||||
inline bool isboolean(lua_State* L, int idx) {
|
||||
inline bool isboolean(lua::State* L, int idx) {
|
||||
return lua_isboolean(L, idx);
|
||||
}
|
||||
inline bool isnumber(lua_State* L, int idx) {
|
||||
inline bool isnumber(lua::State* L, int idx) {
|
||||
return lua_isnumber(L, idx);
|
||||
}
|
||||
inline bool isstring(lua_State* L, int idx) {
|
||||
inline bool isstring(lua::State* L, int idx) {
|
||||
return lua_isstring(L, idx);
|
||||
}
|
||||
inline bool istable(lua_State* L, int idx) {
|
||||
inline bool istable(lua::State* L, int idx) {
|
||||
return lua_istable(L, idx);
|
||||
}
|
||||
inline bool isfunction(lua_State* L, int idx) {
|
||||
inline bool isfunction(lua::State* L, int idx) {
|
||||
return lua_isfunction(L, idx);
|
||||
}
|
||||
inline bool toboolean(lua_State* L, int idx) {
|
||||
inline bool toboolean(lua::State* L, int idx) {
|
||||
return lua_toboolean(L, idx);
|
||||
}
|
||||
inline lua_Integer tointeger(lua_State* L, int idx) {
|
||||
inline lua::Integer tointeger(lua::State* L, int idx) {
|
||||
return lua_tointeger(L, idx);
|
||||
}
|
||||
inline lua_Number tonumber(lua_State* L, int idx) {
|
||||
inline lua::Number tonumber(lua::State* L, int idx) {
|
||||
return lua_tonumber(L, idx);
|
||||
}
|
||||
inline const char* tostring(lua_State* L, int idx) {
|
||||
inline const char* tostring(lua::State* L, int idx) {
|
||||
return lua_tostring(L, idx);
|
||||
}
|
||||
inline const void* topointer(lua_State* L, int idx) {
|
||||
inline const void* topointer(lua::State* L, int idx) {
|
||||
return lua_topointer(L, idx);
|
||||
}
|
||||
inline glm::vec2 tovec2(lua_State* L, int idx) {
|
||||
inline glm::vec2 tovec2(lua::State* L, int idx) {
|
||||
pushvalue(L, idx);
|
||||
if (!istable(L, idx) || objlen(L, idx) < 2) {
|
||||
throw std::runtime_error("value must be an array of two numbers");
|
||||
@ -251,7 +258,7 @@ namespace lua {
|
||||
return glm::vec2(x, y);
|
||||
}
|
||||
|
||||
inline glm::vec4 tocolor(lua_State* L, int idx) {
|
||||
inline glm::vec4 tocolor(lua::State* L, int idx) {
|
||||
pushvalue(L, idx);
|
||||
if (!istable(L, -1) || objlen(L, idx) < 4) {
|
||||
throw std::runtime_error("RGBA array required");
|
||||
@ -268,10 +275,10 @@ namespace lua {
|
||||
return glm::vec4(r/255, g/255, b/255, a/255);
|
||||
}
|
||||
|
||||
int pushvalue(lua_State*, const dynamic::Value& value);
|
||||
dynamic::Value tovalue(lua_State*, int idx);
|
||||
int pushvalue(lua::State*, const dynamic::Value& value);
|
||||
dynamic::Value tovalue(lua::State*, int idx);
|
||||
|
||||
inline bool getfield(lua_State* L, const std::string& name, int idx=-1) {
|
||||
inline bool getfield(lua::State* L, const std::string& name, int idx=-1) {
|
||||
lua_getfield(L, idx, name.c_str());
|
||||
if (isnil(L, -1)) {
|
||||
pop(L);
|
||||
@ -280,26 +287,26 @@ namespace lua {
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void setfield(lua_State* L, const std::string& name, int idx=-2) {
|
||||
inline void setfield(lua::State* L, const std::string& name, int idx=-2) {
|
||||
lua_setfield(L, idx, name.c_str());
|
||||
}
|
||||
|
||||
inline void setglobal(lua_State* L, const std::string& name) {
|
||||
inline void setglobal(lua::State* L, const std::string& name) {
|
||||
lua_setglobal(L, name.c_str());
|
||||
}
|
||||
|
||||
inline const char* require_string(lua_State* L, int idx) {
|
||||
inline const char* require_string(lua::State* L, int idx) {
|
||||
if (!isstring(L, idx)) {
|
||||
throw luaerror("string expected at "+std::to_string(idx));
|
||||
}
|
||||
return tostring(L, idx);
|
||||
}
|
||||
|
||||
std::wstring require_wstring(lua_State*, int idx);
|
||||
std::wstring require_wstring(lua::State*, int idx);
|
||||
|
||||
inline bool rename(lua_State* L, const std::string& from, const std::string& to) {
|
||||
inline bool rename(lua::State* L, const std::string& from, const std::string& to) {
|
||||
getglobal(L, from);
|
||||
if (lua_isnil(L, -1)) {
|
||||
if (isnil(L, -1)) {
|
||||
pop(L, 1);
|
||||
return false;
|
||||
}
|
||||
@ -311,12 +318,12 @@ namespace lua {
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void remove(lua_State* L, const std::string& name) {
|
||||
inline void remove(lua::State* L, const std::string& name) {
|
||||
pushnil(L);
|
||||
setglobal(L, name);
|
||||
}
|
||||
|
||||
inline void loadbuffer(lua_State* L, int env, const std::string& src, const std::string& file) {
|
||||
inline void loadbuffer(lua::State* L, int env, const std::string& src, const std::string& file) {
|
||||
if (luaL_loadbuffer(L, src.c_str(), src.length(), file.c_str())) {
|
||||
throw luaerror(tostring(L, -1));
|
||||
}
|
||||
@ -325,39 +332,39 @@ namespace lua {
|
||||
}
|
||||
}
|
||||
|
||||
int call(lua_State*, int argc, int nresults=-1);
|
||||
int call_nothrow(lua_State*, int argc);
|
||||
int call(lua::State*, int argc, int nresults=-1);
|
||||
int call_nothrow(lua::State*, int argc);
|
||||
|
||||
inline int eval(lua_State* L, int env, const std::string& src, const std::string& file="<eval>") {
|
||||
inline int eval(lua::State* L, int env, const std::string& src, const std::string& file="<eval>") {
|
||||
auto srcText = "return "+src;
|
||||
loadbuffer(L, env, srcText, file);
|
||||
return call(L, 0);
|
||||
}
|
||||
|
||||
inline int execute(lua_State* L, int env, const std::string& src, const std::string& file="<eval>") {
|
||||
inline int execute(lua::State* L, int env, const std::string& src, const std::string& file="<eval>") {
|
||||
loadbuffer(L, env, src, file);
|
||||
return call_nothrow(L, 0);
|
||||
}
|
||||
|
||||
runnable create_runnable(lua_State*);
|
||||
scripting::common_func create_lambda(lua_State* );
|
||||
runnable create_runnable(lua::State*);
|
||||
scripting::common_func create_lambda(lua::State* );
|
||||
|
||||
inline int pushenv(lua_State* L, int env) {
|
||||
inline int pushenv(lua::State* L, int env) {
|
||||
if (getglobal(L, env_name(env))) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int createEnvironment(lua_State*, int parent);
|
||||
void removeEnvironment(lua_State*, int id);
|
||||
void dump_stack(lua_State*);
|
||||
int createEnvironment(lua::State*, int parent);
|
||||
void removeEnvironment(lua::State*, int id);
|
||||
void dump_stack(lua::State*);
|
||||
|
||||
inline void addfunc(lua_State* L, const std::string& name, lua_CFunction func) {
|
||||
inline void addfunc(lua::State* L, const std::string& name, lua_CFunction func) {
|
||||
pushcfunction(L, func);
|
||||
setglobal(L, name);
|
||||
}
|
||||
|
||||
inline void openlib(lua_State* L, const std::string& name, const luaL_Reg* libfuncs) {
|
||||
inline void openlib(lua::State* L, const std::string& name, const luaL_Reg* libfuncs) {
|
||||
createtable(L, 0, 0);
|
||||
luaL_setfuncs(L, libfuncs, 0);
|
||||
setglobal(L, name);
|
||||
|
||||
@ -154,28 +154,28 @@ void scripting::on_world_quit() {
|
||||
|
||||
void scripting::on_blocks_tick(const Block* block, int tps) {
|
||||
std::string name = block->name + ".blockstick";
|
||||
lua::emit_event(lua::get_main_thread(), name, [tps] (lua_State* L) {
|
||||
lua::emit_event(lua::get_main_thread(), name, [tps] (auto L) {
|
||||
return lua::pushinteger(L, tps);
|
||||
});
|
||||
}
|
||||
|
||||
void scripting::update_block(const Block* block, int x, int y, int z) {
|
||||
std::string name = block->name + ".update";
|
||||
lua::emit_event(lua::get_main_thread(), name, [x, y, z] (lua_State* L) {
|
||||
lua::emit_event(lua::get_main_thread(), name, [x, y, z] (auto L) {
|
||||
return lua::pushivec3(L, x, y, z);
|
||||
});
|
||||
}
|
||||
|
||||
void scripting::random_update_block(const Block* block, int x, int y, int z) {
|
||||
std::string name = block->name + ".randupdate";
|
||||
lua::emit_event(lua::get_main_thread(), name, [x, y, z] (lua_State* L) {
|
||||
lua::emit_event(lua::get_main_thread(), name, [x, y, z] (auto L) {
|
||||
return lua::pushivec3(L, x, y, z);
|
||||
});
|
||||
}
|
||||
|
||||
void scripting::on_block_placed(Player* player, const Block* block, int x, int y, int z) {
|
||||
std::string name = block->name + ".placed";
|
||||
lua::emit_event(lua::get_main_thread(), name, [x, y, z, player] (lua_State* L) {
|
||||
lua::emit_event(lua::get_main_thread(), name, [x, y, z, player] (auto L) {
|
||||
lua::pushivec3(L, x, y, z);
|
||||
lua::pushinteger(L, player->getId());
|
||||
return 4;
|
||||
@ -184,7 +184,7 @@ void scripting::on_block_placed(Player* player, const Block* block, int x, int y
|
||||
|
||||
void scripting::on_block_broken(Player* player, const Block* block, int x, int y, int z) {
|
||||
std::string name = block->name + ".broken";
|
||||
lua::emit_event(lua::get_main_thread(), name, [x, y, z, player] (lua_State* L) {
|
||||
lua::emit_event(lua::get_main_thread(), name, [x, y, z, player] (auto L) {
|
||||
lua::pushivec3(L, x, y, z);
|
||||
lua::pushinteger(L, player->getId());
|
||||
return 4;
|
||||
@ -193,7 +193,7 @@ void scripting::on_block_broken(Player* player, const Block* block, int x, int y
|
||||
|
||||
bool scripting::on_block_interact(Player* player, const Block* block, glm::ivec3 pos) {
|
||||
std::string name = block->name + ".interact";
|
||||
return lua::emit_event(lua::get_main_thread(), name, [pos, player] (lua_State* L) {
|
||||
return lua::emit_event(lua::get_main_thread(), name, [pos, player] (auto L) {
|
||||
lua::pushivec3(L, pos.x, pos.y, pos.z);
|
||||
lua::pushinteger(L, player->getId());
|
||||
return 4;
|
||||
@ -202,14 +202,14 @@ bool scripting::on_block_interact(Player* player, const Block* block, glm::ivec3
|
||||
|
||||
bool scripting::on_item_use(Player* player, const ItemDef* item) {
|
||||
std::string name = item->name + ".use";
|
||||
return lua::emit_event(lua::get_main_thread(), name, [player] (lua_State* L) {
|
||||
return lua::emit_event(lua::get_main_thread(), name, [player] (lua::State* L) {
|
||||
return lua::pushinteger(L, player->getId());
|
||||
});
|
||||
}
|
||||
|
||||
bool scripting::on_item_use_on_block(Player* player, const ItemDef* item, int x, int y, int z) {
|
||||
std::string name = item->name + ".useon";
|
||||
return lua::emit_event(lua::get_main_thread(), name, [x, y, z, player] (lua_State* L) {
|
||||
return lua::emit_event(lua::get_main_thread(), name, [x, y, z, player] (auto L) {
|
||||
lua::pushivec3(L, x, y, z);
|
||||
lua::pushinteger(L, player->getId());
|
||||
return 4;
|
||||
@ -218,7 +218,7 @@ bool scripting::on_item_use_on_block(Player* player, const ItemDef* item, int x,
|
||||
|
||||
bool scripting::on_item_break_block(Player* player, const ItemDef* item, int x, int y, int z) {
|
||||
std::string name = item->name + ".blockbreakby";
|
||||
return lua::emit_event(lua::get_main_thread(), name, [x, y, z, player] (lua_State* L) {
|
||||
return lua::emit_event(lua::get_main_thread(), name, [x, y, z, player] (auto L) {
|
||||
lua::pushivec3(L, x, y, z);
|
||||
lua::pushinteger(L, player->getId());
|
||||
return 4;
|
||||
@ -231,7 +231,7 @@ void scripting::on_ui_open(
|
||||
) {
|
||||
auto argsptr = std::make_shared<std::vector<dynamic::Value>>(std::move(args));
|
||||
std::string name = layout->getId() + ".open";
|
||||
lua::emit_event(lua::get_main_thread(), name, [=] (lua_State* L) {
|
||||
lua::emit_event(lua::get_main_thread(), name, [=] (auto L) {
|
||||
for (const auto& value : *argsptr) {
|
||||
lua::pushvalue(L, value);
|
||||
}
|
||||
@ -241,7 +241,7 @@ void scripting::on_ui_open(
|
||||
|
||||
void scripting::on_ui_progress(UiDocument* layout, int workDone, int workTotal) {
|
||||
std::string name = layout->getId() + ".progress";
|
||||
lua::emit_event(lua::get_main_thread(), name, [=] (lua_State* L) {
|
||||
lua::emit_event(lua::get_main_thread(), name, [=] (auto L) {
|
||||
lua::pushinteger(L, workDone);
|
||||
lua::pushinteger(L, workTotal);
|
||||
return 2;
|
||||
@ -250,7 +250,7 @@ void scripting::on_ui_progress(UiDocument* layout, int workDone, int workTotal)
|
||||
|
||||
void scripting::on_ui_close(UiDocument* layout, Inventory* inventory) {
|
||||
std::string name = layout->getId() + ".close";
|
||||
lua::emit_event(lua::get_main_thread(), name, [inventory] (lua_State* L) {
|
||||
lua::emit_event(lua::get_main_thread(), name, [inventory] (auto L) {
|
||||
return lua::pushinteger(L, inventory ? inventory->getId() : 0);
|
||||
});
|
||||
}
|
||||
|
||||
@ -23,7 +23,7 @@ runnable scripting::create_runnable(
|
||||
}
|
||||
}
|
||||
|
||||
static lua_State* process_callback(
|
||||
static lua::State* process_callback(
|
||||
const scriptenv& env,
|
||||
const std::string& src,
|
||||
const std::string& file
|
||||
|
||||
@ -22,7 +22,7 @@ void scripting::on_frontend_init(Hud* hud) {
|
||||
|
||||
for (auto& pack : engine->getContentPacks()) {
|
||||
lua::emit_event(lua::get_main_thread(), pack.id + ".hudopen",
|
||||
[&] (lua_State* L) {
|
||||
[&] (lua::State* L) {
|
||||
return lua::pushinteger(L, hud->getPlayer()->getId());
|
||||
});
|
||||
}
|
||||
@ -31,7 +31,7 @@ void scripting::on_frontend_init(Hud* hud) {
|
||||
void scripting::on_frontend_close() {
|
||||
for (auto& pack : engine->getContentPacks()) {
|
||||
lua::emit_event(lua::get_main_thread(), pack.id + ".hudclose",
|
||||
[&] (lua_State* L) {
|
||||
[&] (lua::State* L) {
|
||||
return lua::pushinteger(L, hud->getPlayer()->getId());
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user