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