aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Belle-Isle <drumsetmonkey@gmail.com>2019-09-03 02:22:39 -0400
committerAndy Belle-Isle <drumsetmonkey@gmail.com>2019-09-03 02:22:39 -0400
commit9c9f72c29a71a1813e9bc42d57998676237b57e3 (patch)
tree248f042a14b3f889cf0eb616d2776fd1fb514450
parentaa7b0a92d065b4435467d482ec65dd97b03459ee (diff)
Start working on Lua function serialization
-rw-r--r--Scripts/init.lua39
-rw-r--r--src/script.cpp4
2 files changed, 41 insertions, 2 deletions
diff --git a/Scripts/init.lua b/Scripts/init.lua
index 4a874b2..6d225f5 100644
--- a/Scripts/init.lua
+++ b/Scripts/init.lua
@@ -86,7 +86,10 @@ animal = {
self.Velocity.y = 500 * math.cos(math.rad(self.counter*5));
self.counter = self.counter + 5;
end,
- counter = 0;
+ counter = 0,
+ TestMe = function(self)
+ print("Light: rgb("..self.Light.r..","..self.Light.g..","..self.Light.b..")")
+ end
}
wall = {
@@ -126,3 +129,37 @@ game.spawn({
self.counter = self.counter + 5;
end
});
+
+-------------------
+-- SERIALIZING --
+-------------------
+
+function serial (before_ser)
+ binary = string.dump(before_ser)
+ formatted_binary = ""
+ for i = 1, string.len(binary) do
+ dec, _ = ("\\%3d"):format(binary:sub(i, i):byte()):gsub(' ', '0')
+ formatted_binary = formatted_binary .. dec
+ end
+ return formatted_binary
+end
+
+function hello(herro)
+ print("Hello world ".. herro)
+end
+
+--print(serial(hello))
+
+local ser = string.dump(hello)
+f2 = (loadstring or load)(ser)
+f2("shite")
+
+local testPut = string.dump(animalSpawn.TestMe)
+testRun = (loadstring or load)(testPut)
+testRun(animalSpawn)
+
+--blah = load(serial(hello))
+--blah()
+
+--draw = loadstring("\027\076\074\001\000\009\064\109\097\105\110\046\108\117\097\084\000\000\004\000\004\000\008\009\002\002\052\000\000\000\055\000\001\000\055\000\002\000\037\001\003\000\039\002\010\000\039\003\010\000\062\000\004\001\071\000\001\000\017\104\101\108\108\111\044\032\119\111\114\108\100\010\112\114\105\110\116\013\103\114\097\112\104\105\099\115\009\108\111\118\101\001\001\001\001\001\001\001\002\000\000")
+--draw()
diff --git a/src/script.cpp b/src/script.cpp
index fa485bc..351aae4 100644
--- a/src/script.cpp
+++ b/src/script.cpp
@@ -57,7 +57,7 @@ void ScriptSystem::receive([[maybe_unused]] const EntitySpawnEvent &toSpawn)
int ScriptSystem::init(void)
{
- lua.open_libraries(sol::lib::base, sol::lib::math);
+ lua.open_libraries(sol::lib::base, sol::lib::math, sol::lib::string);
scriptExport();
doFile();
@@ -176,6 +176,8 @@ sol::table ScriptSystem::spawn(sol::object param)
}
if (tab["Light"] != nullptr) {
+ if (!e.has_component<Position>()) // Position must exist for vel.
+ (*toRet)["Position"] = e.assign<Position>().get();
(*toRet)["Light"] =
e.assign<Light>(Light().FromLua(tab["Light"])).get();
}