78 lines
2.8 KiB
C++
78 lines
2.8 KiB
C++
#include "luastack.hpp"
|
|
#include "globaldb.hpp"
|
|
|
|
|
|
LuaDefine(global_set, "varname, value",
|
|
"|Store data in the global data table."
|
|
"|"
|
|
"|The variable name must be a string which is a valid"
|
|
"|lua identifier."
|
|
"|"
|
|
"|You can store global data using global.set, then you can"
|
|
"|retrieve it using global.get. You can also retrieve data using"
|
|
"|gv.varname, which is just shorthand for global.get. You may not"
|
|
"|store data using gv.varname=value, this yields the error 'Use "
|
|
"|global.set to store data in the global data table.'"
|
|
"|"
|
|
"|Values stored using global.set are transmitted to all"
|
|
"|connected clients immediately. When a new client connects,"
|
|
"|he will receive all the global data."
|
|
"|"
|
|
"|The global data table is not the same thing as the lua "
|
|
"|environment table. Trying to store data in the lua environment"
|
|
"|table will seem to work, at first, but the data will not get"
|
|
"|difference transmitted, and will eventually be cleared and lost."
|
|
"|Therefore, it is essential that global data be stored in the"
|
|
"|global data table (using global.set) instead of in the lua"
|
|
"|environment table."
|
|
"|"
|
|
"|There are certain restrictions on the values that you store."
|
|
"|The value can contain strings, numbers, simple tables, and"
|
|
"|tangibles. Nothing else is allowed. Simple tables are tables"
|
|
"|that don't have metatables, and that aren't special tables such"
|
|
"|as classes, the lua environment table, the registry, or the like."
|
|
"|"
|
|
"|When you store the value, a recursive copy is made and stored."
|
|
"|When you call global.get, you obtain the copy. Any attempt to"
|
|
"|mutate the copy will fail with this lua error message: 'Tables"
|
|
"|returned by global.get are immutable.' This rule prevents'"
|
|
"|aliasing between global data and other data structures."
|
|
"|") {
|
|
return 0;
|
|
}
|
|
|
|
LuaDefine(global_get, "varname",
|
|
"|Get data stored using global.set"
|
|
"|"
|
|
"|See doc(global.set) for information on how to store global data."
|
|
"|") {
|
|
return 0;
|
|
}
|
|
|
|
LuaDefine(global_once, "name",
|
|
"|For a given string, returns true exactly once"
|
|
"|"
|
|
"|The semantics and difference transmission behavior of global.once"
|
|
"|are identical to the semantics of global.set, since global.once"
|
|
"|uses global.set under the covers."
|
|
"|") {
|
|
LuaArg name;
|
|
LuaRet flag;
|
|
LuaVar oncedb, val;
|
|
LuaStack LS(L, name, flag, oncedb, val);
|
|
return 0;
|
|
}
|
|
|
|
LuaDefine(global_clearonce, "name",
|
|
"|Reset the specified once-flag"
|
|
"|"
|
|
"|The semantics and difference transmission behavior of global.clearonce"
|
|
"|are identical to the semantics of global.set, since global.once"
|
|
"|uses global.set under the covers."
|
|
"|") {
|
|
LuaArg name;
|
|
LuaVar oncedb;
|
|
LuaStack LS(L, name, oncedb);
|
|
return 0;
|
|
}
|