https://github.com/imerr/serpentcpp
C++ Serpent Loader
https://github.com/imerr/serpentcpp
cpp cpp11 lua serpent
Last synced: about 2 months ago
JSON representation
C++ Serpent Loader
- Host: GitHub
- URL: https://github.com/imerr/serpentcpp
- Owner: imerr
- License: mit
- Created: 2017-02-10T02:26:24.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-02-21T13:23:15.000Z (over 9 years ago)
- Last Synced: 2026-04-26T11:20:46.858Z (about 2 months ago)
- Topics: cpp, cpp11, lua, serpent
- Language: C++
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SerpentCpp
C++11 Serpent Loader
Loads basic serpent strings
### Limitations:
* Numbers are stored as double - so a loss of precision may happen
* Loads tables in a recursive manner - so it might cause a stack overflow if it's nested too deeply
* This was written to load fairly basic tables - so more specific lua things might break. Do tell if they do and I'll look at fixing things
### Usage
```c++
std::string serpentString = "do local _={keyHere=5,{wowNested={moreNesting=\"string\",false=true}}}; return _; end";
try {
Serpent serpent = Serpent::Load(serpentString);
Serpent& someChild = serpent["keyHere"];
if (!someChild.IsNull()) {
if (someChild.IsNumber()) {
std::cout << "'keyHere' is " << someChild.As() << std::endl;
} else {
std::cerr << "'keyHere' is not a number :( "<< someChild.Type() << std::endl;
}
} else {
std::cerr << "'keyHere' does not exist" << std::endl;
}
if (serpent[1]["wowNested"][false].IsBool() && serpent[1]["wowNested"][false].As()) {
std::cout << "Nesting and indexing by bool seems to work fine too" << std::endl;
} else {
std::cerr << "Nesting and indexing by bool is broken :(" << std::endl;
}
} catch (Serpent::Exception e) {
// Uh Oh - something went wrong
std::cerr << "Something went: " << std::endl
<< e.what() << std::endl;
}
```