Skip to content
This repository has been archived by the owner on Oct 31, 2021. It is now read-only.

Commit

Permalink
slightly changed the ShinyLua interface
Browse files Browse the repository at this point in the history
  • Loading branch information
aidinabedi committed Dec 26, 2009
1 parent a8d41b2 commit 7d816f1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 21 deletions.
8 changes: 5 additions & 3 deletions ShinyLua/include/ShinyLua.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ extern "C" {
SHINY_EXPORT int ShinyLua_update(lua_State *L);
SHINY_EXPORT int ShinyLua_clear(lua_State *L);
SHINY_EXPORT int ShinyLua_damping(lua_State *L);
SHINY_EXPORT int ShinyLua_enabled(lua_State *L);
SHINY_EXPORT int ShinyLua_start(lua_State *L);
SHINY_EXPORT int ShinyLua_stop(lua_State *L);
SHINY_EXPORT int ShinyLua_is_running(lua_State *L);
SHINY_EXPORT int ShinyLua_output(lua_State *L);
SHINY_EXPORT int ShinyLua_treeString(lua_State *L);
SHINY_EXPORT int ShinyLua_flatString(lua_State *L);
SHINY_EXPORT int ShinyLua_tree_string(lua_State *L);
SHINY_EXPORT int ShinyLua_flat_string(lua_State *L);
}
49 changes: 31 additions & 18 deletions ShinyLua/src/ShinyLua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void callhook(lua_State *L, lua_Debug *ar) {
lua_getinfo(L, "n", ar);
if (!ar->name) return;

if (ar->even == LUA_HOOKCALL) {
if (ar->event == LUA_HOOKCALL) {
Profile *prof = FindProfile(L, ar);
ShinyManager_lookupAndBeginNode(&Shiny_instance, &prof->cache, &prof->zone);
return;
Expand Down Expand Up @@ -195,19 +195,33 @@ int ShinyLua_damping(lua_State *L) {

/*---------------------------------------------------------------------------*/

int ShinyLua_enabled(lua_State *L) {
if (lua_gettop(L) == 1) {
is_running = lua_isboolean(L, -1)? lua_toboolean(L, -1) : luaL_checkint(L, -1);
lua_sethook(L, callhook, is_running? (LUA_MASKCALL | LUA_MASKRET) : 0, 0);
return 0;
int ShinyLua_start(lua_State *L) {
if (is_running) return;
is_running = 1;
lua_sethook(L, callhook, LUA_MASKCALL | LUA_MASKRET, 0);
return 0;
}

} else {
lua_pushboolean(L, is_running);
return 1;
}

/*---------------------------------------------------------------------------*/

int ShinyLua_stop(lua_State *L) {
if (!is_running) return;
is_running = 0;
lua_sethook(L, callhook, 0, 0);
return 0;
}


/*---------------------------------------------------------------------------*/

int ShinyLua_is_running(lua_State *L) {
lua_pushboolean(L, is_running);
return 1;
}



/*---------------------------------------------------------------------------*/

int ShinyLua_output(lua_State *L) {
Expand All @@ -224,15 +238,15 @@ int ShinyLua_output(lua_State *L) {

/*---------------------------------------------------------------------------*/

int ShinyLua_treeString(lua_State *L) {
int ShinyLua_tree_string(lua_State *L) {
lua_pushstring(L, PROFILE_GET_TREE_STRING().c_str());
return 1;
}


/*---------------------------------------------------------------------------*/

int ShinyLua_flatString(lua_State *L) {
int ShinyLua_flat_string(lua_State *L) {
lua_pushstring(L, PROFILE_GET_FLAT_STRING().c_str());
return 1;
}
Expand All @@ -246,15 +260,14 @@ int luaopen_ShinyLua(lua_State *L) {
{ "clear", ShinyLua_clear },
{ "output", ShinyLua_output },
{ "damping", ShinyLua_damping },
{ "enabled", ShinyLua_enabled },
{ "tree_string", ShinyLua_treeString },
{ "flat_string", ShinyLua_flatString },
{ "start", ShinyLua_start },
{ "stop", ShinyLua_stop },
{ "is_running", ShinyLua_is_running },
{ "tree_string", ShinyLua_tree_string },
{ "flat_string", ShinyLua_flat_string },
{ NULL, NULL }
};

is_running = 1;
lua_sethook(L, callhook, LUA_MASKCALL | LUA_MASKRET, 0);

luaL_openlib(L, "shiny", funcs, 0);

lua_pushliteral (L, "_COPYRIGHT");
Expand Down

0 comments on commit 7d816f1

Please sign in to comment.