Skip to content
This repository has been archived by the owner on Aug 26, 2024. It is now read-only.
thatrandomguy43 edited this page Apr 16, 2023 · 9 revisions

Overview

LuaInstance class

The wrapper consists primarily of a class known as LuaInstance, that contains an instance of the Lua interpreter and can be used to execute Lua code. Each instance is independent of every other instance, and has its own global environment. This class is made available by including the LuaInstance.hpp file, but the class methods are defined in LuaInstance.cpp.

Lua type classes

Another header file is also included called LuaTypeClasses.hpp. This defines a few simple classes that represent Lua data types that lack a simple counterpart in C++. These are lua_Table, lua_Function and lua_Userdata.

lua_Value typedef

This type represents a Lua value of an unspecified type, and is defined as the following: std::variant<nullptr_t, bool, void*, lua_Integer, lua_Number, std::string, std::shared_ptr<lua_Table>, lua_CFunction, lua_Function, lua_Userdata>. A table of what types in Lua correspond to what types in C++ is below:

Lua C++
nil nullptr_t
boolean bool
light userdata void*
(integer) number lua_Integer
(non-integer) number lua_Number
string std::string
table std::shared_ptr<lua_Table>
(C) function lua_CFunction
(Lua) function lua_Function
(full) userdata lua_Userdata
thread Not Supported

Other typedefs

lua_Integer, lua_Number and lua_CFunction are all typedefs supplied by the Lua Library. lua_Integer and lua_Number are by default long long int and double respectively, but are intended to be customisable from within luainclude/luaconf.h. Exactly why they are this way is unclear, but it is presumably to allow avoiding more expensive 64-bit math on 32-bit systems.

Lua_CFunction is the type of function pointers to C functions that can be called from Lua. It is defined as int(*)(lua_State*).