MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / contextGetPath

Method contextGetPath

source/core/StarLua.cpp:1012–1041  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1010}
1011
1012LuaValue LuaEngine::contextGetPath(int handleIndex, String path) {
1013 lua_checkstack(m_state, 2);
1014 pushHandle(m_state, handleIndex);
1015
1016 std::string utf8Path = path.takeUtf8();
1017 char* utf8Ptr = &utf8Path[0];
1018 size_t utf8Size = utf8Path.size();
1019
1020 size_t subPathStart = 0;
1021 for (size_t i = 0; i < utf8Size; ++i) {
1022 if (utf8Path[i] == '.') {
1023 utf8Path[i] = '\0';
1024
1025 lua_getfield(m_state, -1, utf8Ptr + subPathStart);
1026 lua_remove(m_state, -2);
1027
1028 if (lua_type(m_state, -1) != LUA_TTABLE) {
1029 lua_pop(m_state, 1);
1030 return LuaNil;
1031 }
1032
1033 subPathStart = i + 1;
1034 }
1035 }
1036
1037 lua_getfield(m_state, -1, utf8Ptr + subPathStart);
1038 lua_remove(m_state, -2);
1039
1040 return popLuaValue(m_state);
1041}
1042
1043void LuaEngine::contextSetPath(int handleIndex, String path, LuaValue const& value) {
1044 lua_checkstack(m_state, 3);

Callers 2

containsPathMethod · 0.80
getPathMethod · 0.80

Calls 5

lua_checkstackFunction · 0.85
lua_getfieldFunction · 0.85
lua_typeFunction · 0.85
takeUtf8Method · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected