Public Types |
typedef lua_CFunction | CFunction |
enum | {
NOREF = LUA_NOREF
} |
enum | {
REFNIL = LUA_REFNIL
} |
enum | {
ANYTAG = LUA_ANYTAG
} |
Public Methods |
| Script (bool initStandardLibrary = true) |
| Script (lua_State* state) |
| ~Script () |
int | GetTop () |
void | SetTop (int index) |
void | PushValue (int index) |
void | Remove (int index) |
void | Insert (int index) |
int | StackSpace () |
Object | GetObject (int index) |
void | PushObject (Object object) |
int | Equal (int index1, int index2) |
int | LessThan (int index1, int index2) |
void | PushBool (bool value) |
void | PushNil () |
void | PushNumber (double n) |
void | PushLString (const char *s, size_t len) |
void | PushString (const char *s) |
void | PushCClosure (lua_CFunction fn, int n) |
void | PushUserTag (void *u, int tag) |
Object | GetGlobal (const char *name) |
void | GetTable (int index) |
void | RawGet (int index) |
void | RawGetI (int index, int n) |
Object | GetGlobals () |
void | GetTagMethod (int tag, const char *event) |
int | GetRef (int ref) |
Object | NewTable () |
void | SetGlobal (const char *name) |
void | SetTable (int index) |
void | RawSet (int index) |
void | RawSetI (int index, int n) |
void | SetGlobals () |
void | SetTagMethod (int tag, const char *event) |
int | Ref (int lock) |
int | Call (int nargs, int nresults) |
void | RawCall (int nargs, int nresults) |
int | DoFile (const char *filename) |
int | DoString (const char *str) |
int | DoBuffer (const char *buff, size_t size, const char *name) |
int | NewTag () |
int | CopyTagMethods (int tagto, int tagfrom) |
void | SetTag (int tag) |
void | Error (const char *s) |
void | Unref (int ref) |
int | Next (int index) |
int | GetN (int index) |
void | Concat (int n) |
void | Pop () |
void | Pop (int amount) |
void | Register (const char* funcName, lua_CFunction function) |
void | PushUserData (void* u) |
void | PushCFunction (lua_CFunction f) |
int | CloneTag (int t) |
bool | IsFunction (int index) |
bool | IsString (int index) |
bool | IsTable (int index) |
bool | IsUserData (int index) |
bool | IsNil (int index) |
bool | IsNull (int index) |
int | ConfigGetInteger (const char* section, const char* entry, int defaultValue = 0) |
float | ConfigGetReal (const char* section, const char* entry, double defaultValue = 0.0) |
const char* | ConfigGetString (const char* section, const char* entry, const char* defaultValue = "") |
void | ConfigSetInteger (const char* section, const char* entry, int value) |
| Assigns [value] to [section].[entry].
|
void | ConfigSetReal (const char* section, const char* entry, double value) |
| Assigns [value] to [section].[entry].
|
void | ConfigSetString (const char* section, const char* entry, const char* value) |
| Assigns [value] to [section].[entry].
|
void | SaveText (const char* filename) |
| Save the complete script state.
|
| operator lua_State * () |
lua_State* | GetState () const |
Public Attributes |
lua_State* | m_state |
bool | m_ownState |
Friends |
class | Object |
#include "Script.h"
static int Script_PrintNumber(lua_State* state)
{
Script script(state);
Script::Object numberObj = script.GetObject(1);
if (numberObj.IsNumber())
printf("%f\n", numberObj.GetNumber());
return 0;
}
static int Script_Add(lua_State* state)
{
Script script(state);
using Script::Object;
Object number1Obj = script.GetObject(1);
Object number2Obj = script.GetObject(2);
if (number1Obj.IsNumber() && number2Obj.IsNumber())
{
script.PushNumber(number1Obj.GetNumber() + number2Obj.GetNumber());
}
else
{
script.PushNumber(0.0f);
}
return 1;
}
void DoScriptIniWriteTest()
{
Script script;
script.ConfigSetReal("Environment", "WindSpeed", 55.0);
script.ConfigSetString("Environment", "TypeStr", "Overcast");
script.ConfigSetInteger("AnotherGroup", "IntegerValue", 1);
script.SaveText("ScriptIniTest.dmp");
}
void DoScriptIniReadTest()
{
Script script;
script.DoFile("ScriptIniTest.dmp");
float windSpeed = script.ConfigGetReal("Environment", "WindSpeed", 0.0);
const char* typeStr = script.ConfigGetString("Environment", "TypeStr", "Clear");
int integerValue = script.ConfigGetInteger("AnotherGroup", "IntegerValue");
}
void DoScriptCallbackTest()
{
Script script;
script.Register("PrintNumber", Script_PrintNumber);
script.Register("Add", Script_Add);
script.DoFile("ScriptCallbackTest.scr");
}
void DoScriptSaveTest()
{
Script script;
script.DoFile("ScriptSaveTest.scr");
script.SaveText("ScriptSaveTest.dmp");
}
void DoScriptArrayTest()
{
Script script;
script.DoFile("ScriptArrayTest.scr");
Script::Object testTableObj = script.GetGlobals().GetByName("TestArray");
for (int i = 1; ; ++i)
{
Script::AutoBlock block(script);
Script::Object entryObj = testTableObj.GetByIndex(i);
if (entryObj.IsNil())
break;
if (entryObj.IsNumber())
printf("%f\n", entryObj.GetNumber());
else if (entryObj.IsString())
printf("%s\n", entryObj.GetString());
}
}
int main(int argc, char* argv[])
{
DoScriptIniWriteTest();
DoScriptIniReadTest();
DoScriptCallbackTest();
DoScriptSaveTest();
DoScriptArrayTest();
return 0;
}