A few missing constants in math module
This commit is contained in:
@@ -2,10 +2,7 @@ Calling out to external servers.
|
|||||||
|
|
||||||
Support ANSI escape sequences on output.
|
Support ANSI escape sequences on output.
|
||||||
|
|
||||||
Finish documenting all builtins.
|
Make math.random do something predictable.
|
||||||
|
|
||||||
Get rid of source_install_builtins after documenting all builtins.
|
|
||||||
- but don't forget that source_install_builtins sets the string metatable.
|
|
||||||
|
|
||||||
Do something about std::cerr && std::cout once and for all.
|
Do something about std::cerr && std::cout once and for all.
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
LuaDefine(makeclass, "classname", "create a class if it doesn't already exist") {
|
LuaDefine(makeclass, "classname", "create a class if it doesn't already exist") {
|
||||||
LuaArg classname;
|
LuaArg classname;
|
||||||
@@ -338,9 +339,18 @@ static eng::string source_load_lfunctions(lua_State *L) {
|
|||||||
|
|
||||||
eng::string SourceDB::rebuild() {
|
eng::string SourceDB::rebuild() {
|
||||||
lua_State *L = lua_state_;
|
lua_State *L = lua_state_;
|
||||||
|
LuaVar mathclass;
|
||||||
|
LuaStack LS(L, mathclass);
|
||||||
source_clear_globals(L);
|
source_clear_globals(L);
|
||||||
source_load_cfunctions(L);
|
source_load_cfunctions(L);
|
||||||
eng::string errs = source_load_lfunctions(L);
|
eng::string errs = source_load_lfunctions(L);
|
||||||
|
|
||||||
|
// A few builtin constants. These are hardwired.
|
||||||
|
LS.makeclass(mathclass, "math");
|
||||||
|
LS.rawset(mathclass, "pi", M_PI);
|
||||||
|
LS.rawset(mathclass, "huge", HUGE_VAL);
|
||||||
|
|
||||||
|
LS.result();
|
||||||
return errs;
|
return errs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -385,20 +395,20 @@ void SourceDB::init(lua_State *L) {
|
|||||||
lua_state_ = L;
|
lua_state_ = L;
|
||||||
LuaVar globtab, persist, unpersist, classname, classtab, funcname, funcp, rawfunc, nullstring;
|
LuaVar globtab, persist, unpersist, classname, classtab, funcname, funcp, rawfunc, nullstring;
|
||||||
LuaStack LS(L, globtab, persist, unpersist, classname, classtab, funcname, funcp, rawfunc, nullstring);
|
LuaStack LS(L, globtab, persist, unpersist, classname, classtab, funcname, funcp, rawfunc, nullstring);
|
||||||
|
LS.getglobaltable(globtab);
|
||||||
source_clear_globals(L);
|
LS.rawset(LuaRegistry, "sourcedb", LuaNewTable);
|
||||||
source_load_cfunctions(L);
|
|
||||||
|
|
||||||
// Set the metatable for strings.
|
// Set the metatable for strings.
|
||||||
LS.makeclass(classtab, "string");
|
LS.makeclass(classtab, "string");
|
||||||
LS.set(nullstring, "");
|
LS.set(nullstring, "");
|
||||||
LS.setmetatable(nullstring, classtab);
|
LS.setmetatable(nullstring, classtab);
|
||||||
|
|
||||||
|
// Rebuild the global environment.
|
||||||
|
rebuild();
|
||||||
|
|
||||||
// We need to register all C functions with the eris permanents tables.
|
// We need to register all C functions with the eris permanents tables.
|
||||||
LS.getglobaltable(globtab);
|
|
||||||
LS.rawget(persist, LuaRegistry, "persist");
|
LS.rawget(persist, LuaRegistry, "persist");
|
||||||
LS.rawget(unpersist, LuaRegistry, "unpersist");
|
LS.rawget(unpersist, LuaRegistry, "unpersist");
|
||||||
LS.rawset(LuaRegistry, "sourcedb", LuaNewTable);
|
|
||||||
LS.set(classname, LuaNil);
|
LS.set(classname, LuaNil);
|
||||||
while (LS.next(globtab, classname, classtab) != 0) {
|
while (LS.next(globtab, classname, classtab) != 0) {
|
||||||
if (LS.isstring(classname) && LS.istable(classtab)) {
|
if (LS.isstring(classname) && LS.istable(classtab)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user