Created userdata metatable
This commit is contained in:
@@ -15,7 +15,10 @@ roomManagerAPI.SetOnCreate(function(room, index)
|
|||||||
|
|
||||||
roomAPI.SetOnTick(room, function(room)
|
roomAPI.SetOnTick(room, function(room)
|
||||||
roomAPI.ForEachCharacter(room, function(character)
|
roomAPI.ForEachCharacter(room, function(character)
|
||||||
--
|
--testing the metatables
|
||||||
|
local meta = getmetatable(character)
|
||||||
|
print("", "userdata metatable: ", meta)
|
||||||
|
print(character["trying"])
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
@@ -33,4 +36,8 @@ roomAPI.Initialize(underworld, mapSaver.Load, mapSaver.Save, mapMaker.DebugGrass
|
|||||||
--call the monstrosity
|
--call the monstrosity
|
||||||
doorUtility.createDoorPair("pair 1", overworld, 0, -64, underworld, 0, 0)
|
doorUtility.createDoorPair("pair 1", overworld, 0, -64, underworld, 0, 0)
|
||||||
|
|
||||||
|
--testing the metatables
|
||||||
|
local meta = getmetatable(underworld)
|
||||||
|
print("", "userdata metatable: ", meta)
|
||||||
|
|
||||||
print("Finished the lua script")
|
print("Finished the lua script")
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
//utility functions
|
//utility functions
|
||||||
#include "sql_tools.hpp"
|
#include "sql_tools.hpp"
|
||||||
|
#include "userdata.hpp"
|
||||||
|
|
||||||
//std & STL
|
//std & STL
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
@@ -78,6 +79,21 @@ void ServerApplication::Init(int argc, char* argv[]) {
|
|||||||
|
|
||||||
std::cout << "Initialized lua" << std::endl;
|
std::cout << "Initialized lua" << std::endl;
|
||||||
|
|
||||||
|
//create the userdata metatable
|
||||||
|
lua_pushlightuserdata(luaState, nullptr); //userdata
|
||||||
|
lua_createtable(luaState, 1, 0); //table
|
||||||
|
|
||||||
|
//__index
|
||||||
|
lua_pushstring(luaState, "__index");
|
||||||
|
lua_pushcfunction(luaState, userdataIndex);
|
||||||
|
lua_settable(luaState, -3);
|
||||||
|
|
||||||
|
//set in the object
|
||||||
|
lua_setmetatable(luaState, -2); //set the metatable for userdata
|
||||||
|
lua_pop(luaState, 1); //pop the userdata
|
||||||
|
|
||||||
|
std::cout << "\tCreated userdata metatable" << std::endl;
|
||||||
|
|
||||||
//append config["dir.scripts"] to the module path
|
//append config["dir.scripts"] to the module path
|
||||||
if (config["dir.scripts"].size() > 0) {
|
if (config["dir.scripts"].size() > 0) {
|
||||||
//get the original path
|
//get the original path
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2015
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "userdata.hpp"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int userdataIndex(lua_State* L) {
|
||||||
|
std::cout << "WARNING: userdataIndex called" << std::endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2015
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#ifndef METATABLES_HPP_
|
||||||
|
#define METATABLES_HPP_
|
||||||
|
|
||||||
|
#include "lua.hpp"
|
||||||
|
|
||||||
|
#define TORTUGA_USERDATA_NAME "userdata"
|
||||||
|
|
||||||
|
int userdataIndex(lua_State* L);
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user