23#ifndef CORSIX_TH_TH_LUA_H_
24#define CORSIX_TH_TH_LUA_H_
30#include <initializer_list>
60#if LUA_VERSION_NUM >= 503
70 for (
int i = 0;
i < n;
i++) {
77#if LUA_VERSION_NUM >= 502
84#if LUA_VERSION_NUM >= 502
100template <
class Collection>
102#if LUA_VERSION_NUM >= 502
120#if LUA_VERSION_NUM >= 502
129#if LUA_VERSION_NUM >= 502
144#if LUA_VERSION_NUM >= 502
157#if LUA_VERSION_NUM >= 502
166#if LUA_VERSION_NUM >= 504
168#elif LUA_VERSION_NUM >= 502
188template <
typename T,
typename...
Ts>
219template <
class T,
typename...
Args>
238 static inline const char*
name() {
return "Surface"; }
244 static inline const char*
name() {
return "Map"; }
250 static inline const char*
name() {
return "SpriteSheet"; }
256 static inline const char*
name() {
return "Animation"; }
262 static inline const char*
name() {
return "Animator"; }
268 static inline const char*
name() {
return "Palette"; }
274 static inline const char*
name() {
return "RawBitmap"; }
280 static inline const char*
name() {
return "Font"; }
286 static inline const char*
name() {
return "BitmapFont"; }
292 static inline const char*
name() {
return "FreeTypeFont"; }
298 static inline const char*
name() {
return "Layers"; }
304 static inline const char*
name() {
return "Pathfinder"; }
310 static inline const char*
name() {
return "Cursor"; }
316 static inline const char*
name() {
return "Line"; }
322 static inline const char*
name() {
return "Music"; }
328 static inline const char*
name() {
return "SoundArchive"; }
334 static inline const char*
name() {
return "SoundEffects"; }
340 static inline const char*
name() {
return "Movie"; }
346 static inline const char*
name() {
return "WindowBase"; }
352 static inline const char*
name() {
return "SpriteRenderList"; }
358 static inline const char*
name() {
return "StringProxy"; }
364 static inline const char*
name() {
return "LfsExt"; }
370 static inline const char*
name() {
return "ISO Filesystem"; }
376 static inline const char*
name() {
return "MidiPlayer"; }
391 return static_cast<T*
>(
ud);
418template <
class T,
int mt>
441template <
class T1,
class T2>
449template <
class T1,
class T2,
class T3>
459template <
class T1,
class T2,
class T3,
class T4>
484 std::printf(
"Warn: No metatable for userdata\n");
491 std::printf(
"Warn: No __index field method table for userdata\n");
497 std::printf(
"Warn: No metatable for method table of userdata\n");
504 std::printf(
"Warn: No __class_name field for userdata\n");
520template <
typename B,
typename T1,
typename T2>
522 const std::initializer_list<const char*>&
class_names) {
523 static_assert(std::is_base_of<B, T1>::value,
"B must be a base class for T1");
524 static_assert(std::is_base_of<B, T2>::value,
"B must be a base class for T2");
526 const char* class_name =
nullptr;
530 if (class_name ==
nullptr) {
535 if (std::strcmp(class_name, *
it) == 0) {
537 return static_cast<T1*
>(
p);
540 if (std::strcmp(class_name, *
it) == 0) {
542 return static_cast<T2*
>(
p);
544 std::printf(
"Warn: Unknown class name for usertype %s\n", class_name);
Definition th_lua_ui.cpp:39
Theme Hospital sprite animation manager.
Definition th_gfx.h:234
Definition th_gfx_font.h:139
Definition th_gfx_sdl.h:694
Definition th_gfx_font.h:81
Adaptor around the FreeType2 library to a THFont.
Definition th_gfx_font.h:198
Layer for reading Theme Hospital files out of an .iso disk image.
Definition iso_fs.h:43
Definition th_lua_lfs_ext.cpp:31
Definition th_gfx_sdl.h:715
void operator()(lua_State *L) const
Definition th_lua.h:39
Definition th_movie.h:299
Definition sdl_audio.cpp:43
8bpp palette class.
Definition th_gfx_sdl.h:68
Finds paths through maps.
Definition th_pathfind.h:243
Stored image.
Definition th_gfx_sdl.h:440
Definition th_gfx_sdl.h:247
Utility class for accessing Theme Hospital's SOUND-0.DAT.
Definition th_sound.h:35
Sheet of sprites.
Definition th_gfx_sdl.h:504
Definition th_lua_strings.cpp:60
Definition th_lua_midi.cpp:88
uint32_t mt[N]
Definition random.c:61
Layer information (see animation_manager::draw_frame)
Definition th_gfx.h:190
static const char * name()
Definition th_lua.h:346
static const char * name()
Definition th_lua.h:256
static const char * name()
Definition th_lua.h:262
static const char * name()
Definition th_lua.h:286
static const char * name()
Definition th_lua.h:310
static const char * name()
Definition th_lua.h:280
static const char * name()
Definition th_lua.h:292
static const char * name()
Definition th_lua.h:370
static const char * name()
Definition th_lua.h:298
static const char * name()
Definition th_lua.h:244
static const char * name()
Definition th_lua.h:364
static const char * name()
Definition th_lua.h:316
static const char * name()
Definition th_lua.h:340
static const char * name()
Definition th_lua.h:322
static const char * name()
Definition th_lua.h:268
static const char * name()
Definition th_lua.h:304
static const char * name()
Definition th_lua.h:274
static const char * name()
Definition th_lua.h:238
static const char * name()
Definition th_lua.h:328
static const char * name()
Definition th_lua.h:334
static const char * name()
Definition th_lua.h:352
static const char * name()
Definition th_lua.h:250
static const char * name()
Definition th_lua.h:358
static const char * name()
Definition th_lua.h:376
void luaT_rotate(lua_State *L, int idx, int n)
Lua 5.3 lua_rotate backported to 5.1+.
Definition th_lua.h:59
const char * luaT_checkstring(lua_State *L, int idx, size_t *pLength)
Check that a Lua argument is a string or a proxied string.
Definition th_lua_strings.cpp:624
int luaT_upvalueindex(int i)
Definition th_lua.h:83
int luaT_resume(lua_State *L, lua_State *f, int n, int *nresults)
Definition th_lua.h:165
T * luaT_stdnew(lua_State *L, int mt_idx=luaT_environindex, bool env=false, Args &&... args)
Definition th_lua.h:220
void luaT_execute(lua_State *L, const char *sLuaString)
Definition th_lua.cpp:401
int luaT_stdgc(lua_State *L)
Definition th_lua.h:419
const uint8_t * luaT_checkfile(lua_State *L, int idx, size_t *pDataLen)
Check that a Lua argument is a binary data blob.
Definition th_lua.cpp:155
void luaT_pushcclosure(lua_State *L, lua_CFunction f, int nups)
Definition th_lua.h:128
int luaT_load(lua_State *L, lua_Reader r, void *d, const char *s, const char *m)
Definition th_lua.h:155
void luaT_execute_loadstring(lua_State *L, const char *sLuaString)
Definition th_lua.cpp:360
const int luaT_environindex
Definition th_lua.h:80
int luaopen_th(lua_State *L)
Definition th_lua.cpp:320
T * luaT_new(lua_State *L, Ts... args)
Version of operator new which allocates into a Lua userdata.
Definition th_lua.h:189
int luaT_cpcall(lua_State *L, lua_CFunction f, void *u)
Definition th_lua.h:143
void luaT_getenvfield(lua_State *L, int index, const char *k)
Get a field from the environment table of a value.
Definition th_lua.cpp:65
void luaT_printrawtable(lua_State *L, int idx)
Definition th_lua.cpp:455
void luaT_push(lua_State *L, lua_CFunction f)
Definition th_lua.cpp:412
void luaT_setenvfield(lua_State *L, int index, const char *k)
Set a field on the environment table of a value.
Definition th_lua.cpp:56
std::unique_ptr< lua_State, lua_state_deleter > lua_state_unique_ptr
Unique pointer for lua_State.
Definition th_lua.h:43
void preload_lua_package(lua_State *L, const char *name, lua_CFunction fn)
Definition th_lua.cpp:406
void luaT_register(lua_State *L, const char *n, Collection &l)
Compatibility function for Lua 5.1 luaL_register.
Definition th_lua.h:101
T * luaT_testuserdata(lua_State *L, int idx, int mt_idx, bool required=true)
Definition th_lua.h:380
void luaT_printvalue(lua_State *L, int idx)
Definition th_lua.cpp:424
void luaT_pushcclosuretable(lua_State *L, lua_CFunction fn, int n)
Push a C closure as a callable table.
Definition th_lua.cpp:143
void luaT_setfuncs(lua_State *L, const luaL_Reg *R)
Register functions into the table on top of the stack.
Definition th_lua.h:119
void luaT_printstack(lua_State *L)
Definition th_lua.cpp:442
void luaT_pushtablebool(lua_State *L, const char *k, bool v)
Definition th_lua.cpp:418
B * luaT_touserdata_base(lua_State *L, int idx, const std::initializer_list< const char * > &class_names)
Definition th_lua.h:521
void luaT_pushcfunction(lua_State *L, lua_CFunction f)
Definition th_lua.h:139