fix: lua coroutines support
This commit is contained in:
@@ -14,6 +14,23 @@
|
||||
#include <stdexcept>
|
||||
|
||||
namespace lua {
|
||||
// function wrappers with number of pushed values as return value
|
||||
|
||||
inline int pushnil(lua_State* L) {
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int pushinteger(lua_State* L, lua_Integer x) {
|
||||
lua_pushinteger(L, x);
|
||||
return 1;
|
||||
}
|
||||
|
||||
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) {
|
||||
lua_pushinteger(L, x);
|
||||
lua_pushinteger(L, y);
|
||||
@@ -84,7 +101,6 @@ namespace lua {
|
||||
lua_rawseti(L, -2, 4);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int pushcolor_arr(lua_State* L, glm::vec4 vec) {
|
||||
lua_createtable(L, 4, 0);
|
||||
lua_getglobal(L, "color_mt");
|
||||
@@ -100,6 +116,33 @@ namespace lua {
|
||||
lua_rawseti(L, -2, 4);
|
||||
return 1;
|
||||
}
|
||||
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) {
|
||||
lua_pushstring(L, str.c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int pushwstring(lua_State* L, const std::wstring& str);
|
||||
|
||||
inline int pushboolean(lua_State* L, bool value) {
|
||||
lua_pushboolean(L, value);
|
||||
return 1;
|
||||
}
|
||||
inline int pushglobals(lua_State* L) {
|
||||
lua_pushvalue(L, LUA_GLOBALSINDEX);
|
||||
return 1;
|
||||
}
|
||||
inline int pushvalue(lua_State* L, int idx) {
|
||||
lua_pushvalue(L, idx);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline bool toboolean(lua_State* L, int idx) {
|
||||
return lua_toboolean(L, idx);
|
||||
}
|
||||
|
||||
inline glm::vec2 tovec2(lua_State* L, int idx) {
|
||||
lua_pushvalue(L, idx);
|
||||
@@ -130,6 +173,61 @@ namespace lua {
|
||||
lua_pop(L, 1);
|
||||
return glm::vec4(r/255, g/255, b/255, a/255);
|
||||
}
|
||||
|
||||
inline const char* require_string(lua_State* L, int idx) {
|
||||
if (!lua_isstring(L, idx)) {
|
||||
throw luaerror("string expected at "+std::to_string(idx));
|
||||
}
|
||||
return lua_tostring(L, idx);
|
||||
}
|
||||
|
||||
std::wstring require_wstring(lua_State*, int idx);
|
||||
int pushvalue(lua_State*, const dynamic::Value& value);
|
||||
dynamic::Value tovalue(lua_State*, int idx);
|
||||
|
||||
inline void pop(lua_State* L, int n=1) {
|
||||
lua_pop(L, n);
|
||||
}
|
||||
|
||||
inline bool getfield(lua_State* L, const std::string& name, int idx=-1) {
|
||||
lua_getfield(L, idx, name.c_str());
|
||||
if (lua_isnil(L, -1)) {
|
||||
lua_pop(L, -1);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void setfield(lua_State* L, const std::string& name, int idx=-2) {
|
||||
lua_setfield(L, idx, name.c_str());
|
||||
}
|
||||
|
||||
inline bool getglobal(lua_State* L, const std::string& name) {
|
||||
lua_getglobal(L, name.c_str());
|
||||
if (lua_isnil(L, lua_gettop(L))) {
|
||||
lua_pop(L, lua_gettop(L));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool hasglobal(lua_State* L, const std::string& name) {
|
||||
lua_getglobal(L, name.c_str());
|
||||
if (lua_isnil(L, lua_gettop(L))) {
|
||||
lua_pop(L, lua_gettop(L));
|
||||
return false;
|
||||
}
|
||||
lua_pop(L, lua_gettop(L));
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void setglobal(lua_State* L, const std::string& name) {
|
||||
lua_setglobal(L, name.c_str());
|
||||
}
|
||||
|
||||
void logError(const std::string& text);
|
||||
int call(lua_State*, int argc, int nresults=-1);
|
||||
int callNoThrow(lua_State*, int argc);
|
||||
}
|
||||
|
||||
#endif // LOGIC_SCRIPTING_LUA_UTIL_HPP_
|
||||
|
||||
Reference in New Issue
Block a user