json.encode and json.decode finished. Also lots of refactoring.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <climits>
|
||||
|
||||
LuaSpecial LuaRegistry(LUA_REGISTRYINDEX);
|
||||
LuaNilMarker LuaNil;
|
||||
@@ -17,6 +18,15 @@ LuaFunctionReg::LuaFunctionReg(const char *n, const char *a, const char *d, bool
|
||||
All = this;
|
||||
}
|
||||
|
||||
LuaConstantReg::LuaConstantReg(const char *n, const char *d, LuaToken tokenvalue, lua_Number numbervalue) {
|
||||
name_ = n;
|
||||
docs_ = d;
|
||||
tokenvalue_ = tokenvalue;
|
||||
numbervalue_ = numbervalue;
|
||||
next_ = All;
|
||||
All = this;
|
||||
}
|
||||
|
||||
const LuaFunctionReg *LuaFunctionReg::lookup(lua_CFunction fn) {
|
||||
for (const LuaFunctionReg *r = All; r != 0; r = r->next_) {
|
||||
if (r->func_ == fn) {
|
||||
@@ -27,6 +37,20 @@ const LuaFunctionReg *LuaFunctionReg::lookup(lua_CFunction fn) {
|
||||
}
|
||||
|
||||
LuaFunctionReg *LuaFunctionReg::All;
|
||||
LuaConstantReg *LuaConstantReg::All;
|
||||
|
||||
|
||||
eng::string LuaToken::str() const {
|
||||
uint64_t token = (uint64_t)value;
|
||||
char buffer[9];
|
||||
for (int i = 0; i < 8; i++) {
|
||||
unsigned char c = token;
|
||||
buffer[7-i] = c;
|
||||
token >>= 8;
|
||||
}
|
||||
buffer[8] = 0;
|
||||
return eng::string(buffer);
|
||||
}
|
||||
|
||||
static int panicf(lua_State *L) {
|
||||
const char *p = lua_tostring(L, -1);
|
||||
@@ -107,11 +131,23 @@ eng::string LuaStack::ckstring(LuaSlot s) const {
|
||||
return eng::string(str, len);
|
||||
}
|
||||
|
||||
std::string_view LuaStack::ckstringview(LuaSlot s) const {
|
||||
luaL_checktype(L_, s, LUA_TSTRING);
|
||||
size_t len;
|
||||
const char *str = lua_tolstring(L_, s, &len);
|
||||
return std::string_view(str, len);
|
||||
}
|
||||
|
||||
lua_State *LuaStack::ckthread(LuaSlot s) const {
|
||||
luaL_checktype(L_, s, LUA_TTHREAD);
|
||||
return lua_tothread(L_, s);
|
||||
}
|
||||
|
||||
LuaToken LuaStack::cktoken(LuaSlot s) const {
|
||||
luaL_checktype(L_, s, LUA_TLIGHTUSERDATA);
|
||||
return LuaToken(lua_touserdata(L_, s));
|
||||
}
|
||||
|
||||
void LuaStack::count_slots_finalize(int narg, int nvar, int nret) {
|
||||
narg_ = narg;
|
||||
nret_ = nret;
|
||||
|
||||
Reference in New Issue
Block a user