Ideally you would want: Constructor > [optional] Deserialization > Initialization. The nice thing about LUA reading plain text is you can at any point save the state of a lua file (Or lua object as i like to think of it), then read it back in.
Not related to my last post, but here is some pseudocode:
[source lang="cpp"]#include <iostream>class ScriptComponent : Component {protected: WhateverLuaWrapperYouHaveForInternalObject* lua_obj; std::vector<LuaCoroutineWrappers*> lua_coroutines; ScriptComponent(const ScriptComponent&); ScriptComponent& operator=(const ScriptComponent&);public: Component(char* luaFile) { // Some arbitrary way to get your lua "Object" lua_obj = LoadLuaFile(luaFile)->newObject("type"); lua_obj->Awake(); ObjectEnabled(); Start(); } ~Component() { ObjectDisable(); lua_obj->Destroy(); delete lua_obj; } void ObjectEnabled() { lua_obj->OnEnable(); } void ObjectDisable() { lua_obj->OnDisable(); } void Start() { lua_obj->Start(); } void Update(float dt) { lua_obj->Update(dt); for (int i = 0, size = int(lua_coroutines.size()); i < size; ++i) {} lua_coroutines[i]->ProcessYieldingForNull(); lua_coroutines[i]->ProcessYieldingForTime(dt); } } void FixedUpdate(float dt) { // dt being a constant at this point lua_obj->FixedUpdate(dt); for (int i = 0, size = int(lua_coroutines.size()); i < size; ++i) lua_coroutines[i]->ProcessYieldingForFixedUpdate(); } void LateUpdate(float dt) { lua_obj->LateUpdate(dt); for (int i = 0, size = int(lua_coroutines.size()); i < size; ++i) lua_coroutines[i]->ProcessYieldingForEndOfFrame(); } void ObjectWillRender() { lua_obj->OnWillRenderObject(); }};[/source]
Referring to an object lifecycle that looks something like so: