Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial commit for lua script object
- Loading branch information
Showing
6 changed files
with
208 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
* Copyright (c) 2021, University of Washington | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* 3. Neither the name of the University of Washington nor the names of its | ||
* contributors may be used to endorse or promote products derived from this | ||
* software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF WASHINGTON AND CONTRIBUTORS | ||
* “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF WASHINGTON OR | ||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | ||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | ||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | ||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
/****************************************************************************** | ||
* INCLUDES | ||
******************************************************************************/ | ||
|
||
|
||
#include "LuaScript.h" | ||
#include "LuaEngine.h" | ||
#include "core.h" | ||
|
||
/****************************************************************************** | ||
* STATIC DATA | ||
******************************************************************************/ | ||
|
||
const char* LuaScript::OBJECT_TYPE = "LuaScript"; | ||
const char* LuaScript::LuaMetaName = "LuaScript"; | ||
const struct luaL_Reg LuaScript::LuaMetaTable[] = { | ||
{"isactive", luaIsActive}, | ||
{NULL, NULL} | ||
}; | ||
|
||
/****************************************************************************** | ||
* PUBLIC METHODS | ||
******************************************************************************/ | ||
|
||
/*---------------------------------------------------------------------------- | ||
* luaCreate - script(<name>, <script>, <arg>) | ||
*----------------------------------------------------------------------------*/ | ||
int LuaScript::luaCreate (lua_State* L) | ||
{ | ||
try | ||
{ | ||
/* Get Parameters */ | ||
const char* name = getLuaString(L, 1); | ||
const char* script = getLuaString(L, 2); | ||
const char* arg = getLuaString(L, 3, true, NULL); | ||
|
||
/* Return Lua Script Object */ | ||
return createLuaObject(L, new LuaScript(L, name, script, arg)); | ||
} | ||
catch(const RunTimeException& e) | ||
{ | ||
mlog(CRITICAL, "Error creating LuaScript: %s", e.what()); | ||
return returnLuaStatus(L, false); | ||
} | ||
} | ||
|
||
/*---------------------------------------------------------------------------- | ||
* Constructor | ||
*----------------------------------------------------------------------------*/ | ||
LuaScript::LuaScript(lua_State* L, const char* name, const char* script, const char* arg): | ||
LuaObject(L, OBJECT_TYPE, LuaMetaName, LuaMetaTable) | ||
{ | ||
engine = new LuaEngine(name, script, arg, ORIGIN, NULL, false); | ||
} | ||
|
||
/*---------------------------------------------------------------------------- | ||
* Destructor | ||
*----------------------------------------------------------------------------*/ | ||
LuaScript::~LuaScript(void) | ||
{ | ||
delete engine; | ||
} | ||
|
||
/*---------------------------------------------------------------------------- | ||
* luaIsActive - :isactive() | ||
*----------------------------------------------------------------------------*/ | ||
int LuaScript::luaIsActive (lua_State* L) | ||
{ | ||
try | ||
{ | ||
/* Get Self */ | ||
LuaScript* lua_obj = (LuaScript*)getLuaSelf(L, 1); | ||
|
||
/* Return Is Active */ | ||
return returnLuaStatus(L, lua_obj->engine->isActive()); | ||
} | ||
catch(const RunTimeException& e) | ||
{ | ||
mlog(CRITICAL, "Error checking srcipt status: %s", e.what()); | ||
return returnLuaStatus(L, false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright (c) 2021, University of Washington | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* 3. Neither the name of the University of Washington nor the names of its | ||
* contributors may be used to endorse or promote products derived from this | ||
* software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF WASHINGTON AND CONTRIBUTORS | ||
* “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF WASHINGTON OR | ||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | ||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | ||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | ||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#ifndef __lua_script__ | ||
#define __lua_script__ | ||
|
||
/****************************************************************************** | ||
* INCLUDES | ||
******************************************************************************/ | ||
|
||
#include <atomic> | ||
|
||
#include "MsgQ.h" | ||
#include "OsApi.h" | ||
#include "List.h" | ||
#include "StringLib.h" | ||
#include "LuaEngine.h" | ||
#include "LuaObject.h" | ||
#include "EndpointObject.h" | ||
|
||
/****************************************************************************** | ||
* LUA SCRIPT CLASS | ||
******************************************************************************/ | ||
|
||
class LuaScript: public LuaObject | ||
{ | ||
public: | ||
|
||
/*-------------------------------------------------------------------- | ||
* Constants | ||
*--------------------------------------------------------------------*/ | ||
|
||
static const char* OBJECT_TYPE; | ||
static const char* LuaMetaName; | ||
static const struct luaL_Reg LuaMetaTable[]; | ||
|
||
/*-------------------------------------------------------------------- | ||
* Methods | ||
*--------------------------------------------------------------------*/ | ||
|
||
static int luaCreate (lua_State* L); | ||
|
||
LuaScript (lua_State* L, const char* name, const char* script, const char* arg); | ||
~LuaScript (void); | ||
|
||
private: | ||
|
||
|
||
/*-------------------------------------------------------------------- | ||
* Data | ||
*--------------------------------------------------------------------*/ | ||
|
||
LuaEngine* engine; | ||
|
||
/*-------------------------------------------------------------------- | ||
* Methods | ||
*--------------------------------------------------------------------*/ | ||
|
||
static int luaIsActive (lua_State* L); | ||
}; | ||
|
||
#endif /* __lua_script__ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters