-
Notifications
You must be signed in to change notification settings - Fork 0
/
INIBinding.cxx
64 lines (51 loc) · 2.11 KB
/
INIBinding.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//
// Created by secondwtq <lovejay-lovemusic@outlook.com> 2015/07/30.
// Copyright (c) 2015 SCU ISDC All rights reserved.
//
// This file is part of ISDCNext.
//
// We have always treaded the borderland.
//
#include "INIBinding.hxx"
#include "thirdpt/luajit.hxx"
#include "thirdpt/luabridge.hxx"
#include "thirdpt/simpleini.hxx"
class CSimpleIniAWrap {
public:
CSimpleIniAWrap() : m_impl(new CSimpleIniA()) { }
int loadFromString(const std::string& data) {
return static_cast<int>(this->m_impl->LoadData(data)); }
int setValue(const char *section, const char *key, const char *value) {
return static_cast<int>(this->m_impl->SetValue(section, key, value, nullptr, false)); }
int setOrReplaceValue(const char *section, const char *key, const char *value) {
return static_cast<int>(this->m_impl->SetValue(section, key, value, nullptr, true)); }
std::string saveToString() {
std::string ret;
this->m_impl->Save(ret);
return ret;
}
// TODO: should we solve it in mozjs?
int saveToStringRef(std::string& str) {
return static_cast<int>(this->m_impl->Save(str)); }
int saveToFile(const char *filename) {
return static_cast<int>(this->m_impl->SaveFile(filename)); }
~CSimpleIniAWrap() { delete m_impl; }
private:
CSimpleIniA *m_impl;
};
void registerInterfaceINI(lua_State *L) {
luabridge::getGlobalNamespace(L).
beginNamespace("Facer").
// TODO: enum, what we need to provide support in mozjs
// beginClass<SI_Error>("SI_Error").endClass().
beginClass<CSimpleIniAWrap>("CSimpleIniAWrap")
.addConstructor<void (*)()>()
.addFunction("loadFromString", &CSimpleIniAWrap::loadFromString)
.addFunction("saveToString", &CSimpleIniAWrap::saveToString)
.addFunction("saveToStringRef", &CSimpleIniAWrap::saveToStringRef)
.addFunction("saveToFile", &CSimpleIniAWrap::saveToFile)
.addFunction("setValue", &CSimpleIniAWrap::setValue)
.addFunction("setOrReplaceValue", &CSimpleIniAWrap::setOrReplaceValue)
.endClass()
.endNamespace();
}