Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "nwnx_lua"
- int Setup(){
- /*
- function WriteToTestFile(str)
- local file = assert(io.open("D:/test.txt","a"));
- file:write(str);
- file:close();
- end
- */
- //This defines a function that will open a file in append mode and write a string to it and then close
- //We only need to run this once to define the function, once its done its in memory
- RunLuaString("function WriteToTestFile(str) local file = assert(io.open('D:/test.txt','a'));file:write(str);file:close();end");
- }
- int WriteToFile(string str){
- //Here we call the same function we previously defined
- RunLuaString("WriteToTestFile([=["+str+"]=])");
- }
- void SetLuaString(string key, string value){
- /*
- --Ensures the sub table exists
- LOCAL = LOCAL or {};
- --Add the value
- LOCAL['key']='value';
- */
- RunLuaString("LOCAL = LOCAL or {};LOCAL['"+key+"']='"+value+"';");
- }
- string GetLuaString(string key, string def){
- /*
- --Ensures the sub table exists
- LOCAL = LOCAL or {};
- --Return the value from the table to the caller
- return LOCAL['key'];
- */
- string sReturn = RunLuaString("LOCAL = LOCAL or {}; return tostring(LOCAL['"+key+"'])");
- //"nil" in lua means null, it didnt exist, return the default instead
- if(sReturn == "nil")
- return def;
- return sReturn;
- }
- void DeleteLuaString(string key){
- //nil = nothing, setting a value to nil deletes it
- RunLuaString("LOCAL = LOCAL or {};LOCAL['"+key+"']=nil;");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement