Skip to content
This repository has been archived by the owner on Nov 19, 2022. It is now read-only.

Commit

Permalink
Updating cpp-sdk to version 44, implementing readers, bunch of stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
drakeee committed Nov 15, 2020
1 parent 4f9657f commit ea607cf
Show file tree
Hide file tree
Showing 23 changed files with 653 additions and 430 deletions.
14 changes: 9 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,17 @@ add_library(
${PROJECT_SOURCE_FILES}
)

target_compile_definitions(${PROJECT_MODULE_NAME} PRIVATE
-DALT_SERVER_API
)

if(UNIX)
target_link_libraries(${PROJECT_MODULE_NAME} ${PROJECT_SOURCE_DIR}/vendors/luajit/lib/linux64/libluajit.so)
target_compile_options(${PROJECT_MODULE_NAME} PRIVATE
-fuse-ld=lld
-std=c++17
-lstdc++fs
)
#target_compile_options(${PROJECT_MODULE_NAME} PRIVATE
# -fuse-ld=lld
# -std=c++17
# -lstdc++fs
#)
else()
target_link_libraries(${PROJECT_MODULE_NAME}
${PROJECT_SOURCE_DIR}/vendors/luajit/lib/win64/lua51.lib
Expand Down
12 changes: 12 additions & 0 deletions src/CArgReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class CArgReader
{
m_luaVM = L;
m_stackIndex = 1;
m_stackNum = lua_gettop(L);
m_errorOccured = false;
pendingFunctionRefOut = nullptr;
pendingFunctionRef = -1;
Expand All @@ -19,6 +20,16 @@ class CArgReader

}

const char* ToString()
{
return luaL_tolstring(m_luaVM, m_stackIndex++, NULL);
}

int GetArgNum()
{
return m_stackNum;
}

bool IsNextType(int type)
{
return ((lua_type(m_luaVM, m_stackIndex + 1)) == type);
Expand Down Expand Up @@ -409,6 +420,7 @@ class CArgReader
int pendingFunctionRef;

int m_stackIndex;
int m_stackNum;
bool m_errorOccured;

std::vector<std::string> m_errorMessages;
Expand Down
54 changes: 52 additions & 2 deletions src/CLuaDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,14 @@ alt::IBaseObject* lua_tobaseobject(lua_State* L, int idx)
return reinterpret_cast<alt::IBaseObject*>(*((void**)lua_touserdata(L, idx)));
}


int lua_isinteger(lua_State* L, int index)
{
int32_t x = (int32_t)lua_tointeger(L, index);
lua_Number n = lua_tonumber(L, index);
return ((lua_Number)x == n);
}

alt::MValue lua_tomvalue(lua_State* L, int idx)
{
alt::MValue mValue;
Expand All @@ -428,7 +436,10 @@ alt::MValue lua_tomvalue(lua_State* L, int idx)
switch (argType)
{
case LUA_TNUMBER:
mValue = Core->CreateMValueDouble(lua_tonumber(L, idx));
if (lua_isinteger(L, idx))
mValue = Core->CreateMValueInt(lua_tointeger(L, idx));
else
mValue = Core->CreateMValueDouble(lua_tonumber(L, idx));
break;
case LUA_TBOOLEAN:
mValue = Core->CreateMValueBool(lua_toboolean(L, idx));
Expand All @@ -441,7 +452,6 @@ alt::MValue lua_tomvalue(lua_State* L, int idx)
break;
case LUA_TTABLE:
{
//Core->LogInfo("Save table");
auto tempDict = Core->CreateMValueDict();
auto tempList = Core->CreateMValueList();

Expand Down Expand Up @@ -630,4 +640,44 @@ void lua_getdebuginfo(lua_State* L, lua_Debug& debugInfo)
break;
}
}
}

const char* luaL_tolstring(lua_State* L, int idx, size_t* len)
{
if (luaL_callmeta(L, idx, "__tostring"))
{
if (!lua_isstring(L, -1))
luaL_error(L, "'__tostring' must return a string");
}
else {
switch (lua_type(L, idx)) {
case LUA_TNUMBER: {
if (lua_isinteger(L, idx))
lua_pushfstring(L, "%d", lua_tointeger(L, idx));
else
lua_pushfstring(L, "%f", lua_tonumber(L, idx));
break;
}
case LUA_TSTRING:
lua_pushvalue(L, idx);
break;
case LUA_TBOOLEAN:
lua_pushstring(L, (lua_toboolean(L, idx) ? "true" : "false"));
break;
case LUA_TNIL:
lua_pushliteral(L, "nil");
break;
default: {
int tt = luaL_getmetafield(L, idx, "__name"); /* try name */
const char* kind = (tt == LUA_TSTRING) ? lua_tostring(L, -1) :
luaL_typename(L, idx);
lua_pushfstring(L, "%s: %p", kind, lua_topointer(L, idx));
if (tt != LUA_TNIL)
lua_remove(L, -2); /* remove '__name' */
break;
}
}
}

return lua_tolstring(L, -1, len);
}
5 changes: 4 additions & 1 deletion src/CLuaDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,14 @@ void lua_pushresource(lua_State* L, alt::IResource* resource, bool refUserData =
void lua_pushstringarray(lua_State* L, const alt::Array<alt::StringView>& array);
int lua_functionref(lua_State* L, int idx);

int lua_isinteger(lua_State* L, int idx);
void lua_todict(lua_State* L, int idx);
alt::MValue lua_tomvalue(lua_State* L, int indx);
alt::IBaseObject* lua_tobaseobject(lua_State* L, int idx);
//void lua_toentity(lua_State* L, alt::IEntity* entity);

void lua_stacktrace(lua_State* L, const char* stackName = "Unknown");
void lua_dumptable(lua_State* L, int idx, int level = 0);
void lua_getdebuginfo(lua_State* L, lua_Debug& debugInfo);
void lua_getdebuginfo(lua_State* L, lua_Debug& debugInfo);

const char* luaL_tolstring(lua_State* L, int idx, size_t* len);
2 changes: 2 additions & 0 deletions src/CLuaResourceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ bool CLuaResourceImpl::OnEvent(const alt::CEvent* ev)
void CLuaResourceImpl::OnTick()
{

this->TriggerResourceLocalEvent("tick", {});

#ifndef NDEBUG
//this->_core->LogInfo("CLuaResourceImpl::OnTick");
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/CLuaScriptRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

CLuaScriptRuntime::CLuaScriptRuntime()
{
CVehModels::Instance(); //instance class once for further usage
VehicleModels::Instance(); //instance class once for further usage

this->RegisterServerCallback(
alt::CEvent::Type::PLAYER_CONNECT,
Expand Down
2 changes: 1 addition & 1 deletion src/CLuaScriptRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class CLuaScriptRuntime : public alt::IScriptRuntime
~CLuaScriptRuntime() {};

private:
const semver::version version{ 0, 3, 22, semver::prerelease::dev };
const semver::version version{ 0, 4, 0, semver::prerelease::dev };
std::map<lua_State*, CLuaResourceImpl*> resources;
EventsCallbacks eventsCallbacks;
EventsGetter eventsGetter;
Expand Down
62 changes: 0 additions & 62 deletions src/CVehModels.cpp

This file was deleted.

124 changes: 0 additions & 124 deletions src/CVehModels.h

This file was deleted.

0 comments on commit ea607cf

Please sign in to comment.