Luanti 5.11.0-dev
 
Loading...
Searching...
No Matches
c_converter.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5
6/******************************************************************************/
7/******************************************************************************/
8/* WARNING!!!! do NOT add this header in any include file or any code file */
9/* not being a script/modapi file!!!!!!!! */
10/******************************************************************************/
11/******************************************************************************/
12#pragma once
13
14#include <vector>
15#include <string_view>
16
18#include "common/c_types.h"
19
20extern "C" {
21#include <lua.h>
22}
23
24std::string getstringfield_default(lua_State *L, int table,
25 const char *fieldname, const std::string &default_);
26bool getboolfield_default(lua_State *L, int table,
27 const char *fieldname, bool default_);
28float getfloatfield_default(lua_State *L, int table,
29 const char *fieldname, float default_);
30int getintfield_default(lua_State *L, int table,
31 const char *fieldname, int default_);
32
33bool check_field_or_nil(lua_State *L, int index, int type, const char *fieldname);
34
35template<typename T>
36bool getintfield(lua_State *L, int table,
37 const char *fieldname, T &result)
38{
39 lua_getfield(L, table, fieldname);
40 bool got = false;
41 if (check_field_or_nil(L, -1, LUA_TNUMBER, fieldname)){
42 result = lua_tointeger(L, -1);
43 got = true;
44 }
45 lua_pop(L, 1);
46 return got;
47}
48
49// Retrieve an v3s16 where all components are optional (falls back to default)
50v3s16 getv3s16field_default(lua_State *L, int table,
51 const char *fieldname, v3s16 default_);
52
53bool getstringfield(lua_State *L, int table,
54 const char *fieldname, std::string &result);
55bool getstringfield(lua_State *L, int table,
56 const char *fieldname, std::string_view &result);
57size_t getstringlistfield(lua_State *L, int table,
58 const char *fieldname,
59 std::vector<std::string> *result);
60bool getboolfield(lua_State *L, int table,
61 const char *fieldname, bool &result);
62bool getfloatfield(lua_State *L, int table,
63 const char *fieldname, float &result);
64
65void setstringfield(lua_State *L, int table,
66 const char *fieldname, const std::string &value);
67void setintfield(lua_State *L, int table,
68 const char *fieldname, int value);
69void setfloatfield(lua_State *L, int table,
70 const char *fieldname, float value);
71void setboolfield(lua_State *L, int table,
72 const char *fieldname, bool value);
73
74v3f checkFloatPos (lua_State *L, int index);
75v2f check_v2f (lua_State *L, int index);
76v3f check_v3f (lua_State *L, int index);
77v3s16 check_v3s16 (lua_State *L, int index);
78
79v3f read_v3f (lua_State *L, int index);
80v2f read_v2f (lua_State *L, int index);
81v2s16 read_v2s16 (lua_State *L, int index);
82v2s32 read_v2s32 (lua_State *L, int index);
83video::SColor read_ARGB8 (lua_State *L, int index);
84bool read_color (lua_State *L, int index,
85 video::SColor *color);
86bool is_color_table (lua_State *L, int index);
87
88aabb3f read_aabb3f (lua_State *L, int index, f32 scale);
89v3s16 read_v3s16 (lua_State *L, int index);
90std::vector<aabb3f> read_aabb3f_vector (lua_State *L, int index, f32 scale);
91size_t read_stringlist (lua_State *L, int index,
92 std::vector<std::string> *result);
93
94void push_v2s16 (lua_State *L, v2s16 p);
95void push_v2s32 (lua_State *L, v2s32 p);
96void push_v2u32 (lua_State *L, v2u32 p);
97void push_v3s16 (lua_State *L, v3s16 p);
98void push_aabb3f (lua_State *L, aabb3f box, f32 divisor = 1.0f);
99void push_ARGB8 (lua_State *L, video::SColor color);
100void pushFloatPos (lua_State *L, v3f p);
101void push_v3f (lua_State *L, v3f p);
102void push_v2f (lua_State *L, v2f p);
103void push_aabb3f_vector (lua_State *L, const std::vector<aabb3f> &boxes,
104 f32 divisor = 1.0f);
105
106void warn_if_field_exists(lua_State *L, int table,
107 const char *fieldname,
108 std::string_view name,
109 std::string_view message);
110
111size_t write_array_slice_float(lua_State *L, int table_index, float *data,
112 v3u16 data_size, v3u16 slice_offset, v3u16 slice_size);
113
114// This must match the implementation in builtin/game/misc_s.lua
115// Note that this returns a floating point result as Lua integers are 32-bit
116inline lua_Number hash_node_position(v3s16 pos)
117{
118 return (((s64)pos.Z + 0x8000L) << 32)
119 | (((s64)pos.Y + 0x8000L) << 16)
120 | ((s64)pos.X + 0x8000L);
121}
bool check_field_or_nil(lua_State *L, int index, int type, const char *fieldname)
Definition c_converter.cpp:437
std::vector< aabb3f > read_aabb3f_vector(lua_State *L, int index, f32 scale)
Definition c_converter.cpp:371
void warn_if_field_exists(lua_State *L, int table, const char *fieldname, std::string_view name, std::string_view message)
Definition c_content.cpp:1303
void push_ARGB8(lua_State *L, video::SColor color)
Definition c_converter.cpp:216
int getintfield_default(lua_State *L, int table, const char *fieldname, int default_)
Definition c_converter.cpp:547
size_t write_array_slice_float(lua_State *L, int table_index, float *data, v3u16 data_size, v3u16 slice_offset, v3u16 slice_size)
Definition c_converter.cpp:619
size_t read_stringlist(lua_State *L, int index, std::vector< std::string > *result)
Definition c_converter.cpp:409
bool is_color_table(lua_State *L, int index)
Definition c_converter.cpp:305
size_t getstringlistfield(lua_State *L, int table, const char *fieldname, std::vector< std::string > *result)
Definition c_converter.cpp:528
v2f check_v2f(lua_State *L, int index)
Definition c_converter.cpp:153
void push_v2f(lua_State *L, v2f p)
Definition c_converter.cpp:78
void push_v2s16(lua_State *L, v2s16 p)
Definition c_converter.cpp:100
v3s16 check_v3s16(lua_State *L, int index)
Definition c_converter.cpp:256
v3f checkFloatPos(lua_State *L, int index)
Definition c_converter.cpp:235
v3f check_v3f(lua_State *L, int index)
Definition c_converter.cpp:180
void pushFloatPos(lua_State *L, v3f p)
Definition c_converter.cpp:229
bool getstringfield(lua_State *L, int table, const char *fieldname, std::string &result)
Definition c_converter.cpp:471
bool read_color(lua_State *L, int index, video::SColor *color)
Definition c_converter.cpp:263
void push_v3f(lua_State *L, v3f p)
Definition c_converter.cpp:69
v2f read_v2f(lua_State *L, int index)
Definition c_converter.cpp:140
bool getfloatfield(lua_State *L, int table, const char *fieldname, float &result)
Definition c_converter.cpp:500
bool getintfield(lua_State *L, int table, const char *fieldname, T &result)
Definition c_converter.h:36
float getfloatfield_default(lua_State *L, int table, const char *fieldname, float default_)
Definition c_converter.cpp:555
void setintfield(lua_State *L, int table, const char *fieldname, int value)
Definition c_converter.cpp:587
v2s32 read_v2s32(lua_State *L, int index)
Definition c_converter.cpp:127
void setstringfield(lua_State *L, int table, const char *fieldname, const std::string &value)
Definition c_converter.cpp:578
lua_Number hash_node_position(v3s16 pos)
Definition c_converter.h:116
void push_aabb3f_vector(lua_State *L, const std::vector< aabb3f > &boxes, f32 divisor=1.0f)
Definition c_converter.cpp:399
v3f read_v3f(lua_State *L, int index)
Definition c_converter.cpp:170
v2s16 read_v2s16(lua_State *L, int index)
Definition c_converter.cpp:87
std::string getstringfield_default(lua_State *L, int table, const char *fieldname, const std::string &default_)
Definition c_converter.cpp:539
void push_v2s32(lua_State *L, v2s32 p)
Definition c_converter.cpp:109
void push_v2u32(lua_State *L, v2u32 p)
Definition c_converter.cpp:118
video::SColor read_ARGB8(lua_State *L, int index)
Definition c_converter.cpp:282
bool getboolfield_default(lua_State *L, int table, const char *fieldname, bool default_)
Definition c_converter.cpp:563
void setfloatfield(lua_State *L, int table, const char *fieldname, float value)
Definition c_converter.cpp:596
aabb3f read_aabb3f(lua_State *L, int index, f32 scale)
Definition c_converter.cpp:327
v3s16 getv3s16field_default(lua_State *L, int table, const char *fieldname, v3s16 default_)
Definition c_converter.cpp:571
void push_v3s16(lua_State *L, v3s16 p)
Definition c_converter.cpp:240
v3s16 read_v3s16(lua_State *L, int index)
Definition c_converter.cpp:249
bool getboolfield(lua_State *L, int table, const char *fieldname, bool &result)
Definition c_converter.cpp:514
void push_aabb3f(lua_State *L, aabb3f box, f32 divisor=1.0f)
Definition c_converter.cpp:354
void setboolfield(lua_State *L, int table, const char *fieldname, bool value)
Definition c_converter.cpp:605
core::aabbox3d< f32 > aabb3f
Definition irr_aabb3d.h:11
core::vector2d< s32 > v2s32
Definition irr_v2d.h:13
core::vector2d< s16 > v2s16
Definition irr_v2d.h:12
core::vector2d< f32 > v2f
Definition irr_v2d.h:11
core::vector2d< u32 > v2u32
Definition irr_v2d.h:14
core::vector3d< u16 > v3u16
Definition irr_v3d.h:14
core::vector3d< s16 > v3s16
Definition irr_v3d.h:13
core::vector3df v3f
Definition irr_v3d.h:11
static const struct table_key table[]
Definition keycode.cpp:33
static std::string p(std::string path)
Definition test_filesys.cpp:53