本文整理汇总了C#中SharpLua类的典型用法代码示例。如果您正苦于以下问题:C# SharpLua类的具体用法?C# SharpLua怎么用?C# SharpLua使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SharpLua类属于命名空间,在下文中一共展示了SharpLua类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: push
/*
* Pushes the function into the Lua stack
*/
internal void push(SharpLua.Lua.LuaState luaState)
{
if (_Reference != 0)
LuaDLL.lua_getref(luaState, _Reference);
else
_Interpreter.pushCSFunction(function);
}
示例2: LuaInterface
/// <summary>
/// CAUTION: LuaInterface's can't share the same lua state!
/// </summary>
/// <param name="lState"></param>
public LuaInterface(SharpLua.Lua.LuaState lState)
{
lState.initializing = true;
LuaDLL.lua_pushstring(lState, "LUAINTERFACE LOADED");
LuaDLL.lua_gettable(lState, (int)LuaIndexes.LUA_REGISTRYINDEX);
if (LuaDLL.lua_toboolean(lState, -1))
{
LuaDLL.lua_settop(lState, -2);
throw new LuaException("There is already a LuaInterface associated with this LuaState");
}
else
{
LuaDLL.lua_settop(lState, -2);
LuaDLL.lua_pushstring(lState, "LUAINTERFACE LOADED");
LuaDLL.lua_pushboolean(lState, true);
LuaDLL.lua_settable(lState, (int)LuaIndexes.LUA_REGISTRYINDEX);
this.luaState = lState;
LuaDLL.lua_pushvalue(lState, (int)LuaIndexes.LUA_GLOBALSINDEX);
LuaDLL.lua_getglobal(lState, "luanet");
LuaDLL.lua_pushstring(lState, "getmetatable");
LuaDLL.lua_getglobal(lState, "getmetatable");
LuaDLL.lua_settable(lState, -3);
LuaDLL.lua_replace(lState, (int)LuaIndexes.LUA_GLOBALSINDEX);
translator = new ObjectTranslator(this, this.luaState);
LuaDLL.lua_replace(lState, (int)LuaIndexes.LUA_GLOBALSINDEX);
DoString(ScriptStrings.InitLuaNet, "LuaNet");
DoString(ScriptStrings.InitClrLib, "ClrLib");
DoString(ScriptStrings.InitExtLib, "ExtLib");
}
_StatePassed = true;
lState.initializing = false;
}
示例3: createIndexingMetaFunction
/*
* Registers the indexing function of CLR objects
* passed to Lua
*/
private void createIndexingMetaFunction(SharpLua.Lua.LuaState luaState)
{
LuaDLL.lua_pushstring(luaState, "luaNet_indexfunction");
LuaDLL.luaL_dostring(luaState, MetaFunctions.luaIndexFunction); // steffenj: lua_dostring renamed to luaL_dostring
//LuaDLL.lua_pushstdcallcfunction(luaState,indexFunction);
LuaDLL.lua_rawset(luaState, (int)LuaIndexes.LUA_REGISTRYINDEX);
}
示例4: RegisterModule
public void RegisterModule(SharpLua.LuaTypes.LuaTable environment)
{
LuaTable mod = new LuaTable();
RegisterFunctions(mod);
LuaTable mt = new LuaTable();
mt.Register("__newindex", (LuaValue[] args) =>
{
string key = args[1].ToString();
if (key.ToLower() == "key")
{
CryptoLib.key = IExtendFramework.Encryption.SampleObjects.CreateRijndaelKeyWithSHA512(args[2].ToString());
Console.WriteLine("Encryption Key is now " + ByteToString(CryptoLib.key));
}
else if (key.ToLower() == "iv")
{
iv = IExtendFramework.Encryption.SampleObjects.CreateRijndaelIVWithSHA512(args[2].ToString());
Console.WriteLine("Encryption IV is now " + ByteToString(CryptoLib.iv));
}
return LuaNil.Nil;
});
mod.MetaTable = mt;
environment.SetNameValue(ModuleName, mod);
}
示例5: createLuaObjectList
/*
* Sets up the list of objects in the Lua side
*/
private void createLuaObjectList(SharpLua.Lua.LuaState luaState)
{
LuaDLL.lua_pushstring(luaState, "luaNet_objects");
LuaDLL.lua_newtable(luaState);
LuaDLL.lua_newtable(luaState);
LuaDLL.lua_pushstring(luaState, "__mode");
LuaDLL.lua_pushstring(luaState, "v");
LuaDLL.lua_settable(luaState, -3);
LuaDLL.lua_setmetatable(luaState, -2);
LuaDLL.lua_settable(luaState, (int)LuaIndexes.LUA_REGISTRYINDEX);
}
示例6: collectObject
/*
* __gc metafunction of CLR objects.
*/
private int collectObject(SharpLua.Lua.LuaState luaState)
{
int udata = LuaDLL.luanet_rawnetobj(luaState, 1);
if (udata != -1)
{
translator.collectObject(udata);
}
else
{
// Debug.WriteLine("not found: " + udata);
}
return 0;
}
示例7: createBaseClassMetatable
/*
* Creates the metatable for superclasses (the base
* field of registered tables)
*/
private void createBaseClassMetatable(SharpLua.Lua.LuaState luaState)
{
LuaDLL.luaL_newmetatable(luaState, "luaNet_searchbase");
LuaDLL.lua_pushstring(luaState, "__gc");
LuaDLL.lua_pushstdcallcfunction(luaState, metaFunctions.gcFunction);
LuaDLL.lua_settable(luaState, -3);
LuaDLL.lua_pushstring(luaState, "__tostring");
LuaDLL.lua_pushstdcallcfunction(luaState, metaFunctions.toStringFunction);
LuaDLL.lua_settable(luaState, -3);
LuaDLL.lua_pushstring(luaState, "__index");
LuaDLL.lua_pushstdcallcfunction(luaState, metaFunctions.baseIndexFunction);
LuaDLL.lua_settable(luaState, -3);
LuaDLL.lua_pushstring(luaState, "__newindex");
LuaDLL.lua_pushstdcallcfunction(luaState, metaFunctions.newindexFunction);
LuaDLL.lua_settable(luaState, -3);
LuaDLL.lua_settop(luaState, -2);
}
示例8: ObjectTranslator
public ObjectTranslator(LuaInterface interpreter, SharpLua.Lua.LuaState luaState)
{
this.interpreter = interpreter;
typeChecker = new CheckType(this);
metaFunctions = new MetaFunctions(this);
importTypeFunction = new SharpLua.Lua.lua_CFunction(this.importType);
loadAssemblyFunction = new SharpLua.Lua.lua_CFunction(this.loadAssembly);
registerTableFunction = new SharpLua.Lua.lua_CFunction(this.registerTable);
unregisterTableFunction = new SharpLua.Lua.lua_CFunction(this.unregisterTable);
getMethodSigFunction = new SharpLua.Lua.lua_CFunction(this.getMethodSignature);
getConstructorSigFunction = new SharpLua.Lua.lua_CFunction(this.getConstructorSignature);
ctypeFunction = new SharpLua.Lua.lua_CFunction(this.ctype);
enumFromIntFunction = new SharpLua.Lua.lua_CFunction(this.enumFromInt);
createLuaObjectList(luaState);
createIndexingMetaFunction(luaState);
createBaseClassMetatable(luaState);
createClassMetatable(luaState);
createFunctionMetatable(luaState);
setGlobalFunctions(luaState);
}
示例9: getAsBoolean
private object getAsBoolean(SharpLua.Lua.LuaState luaState, int stackPos)
{
return LuaDLL.lua_toboolean(luaState, stackPos);
}
示例10: getAsDecimal
private object getAsDecimal(SharpLua.Lua.LuaState luaState, int stackPos)
{
decimal retVal = (decimal)LuaDLL.lua_tonumber(luaState, stackPos);
if (retVal == 0 && !LuaDLL.lua_isnumber(luaState, stackPos)) return null;
return retVal;
}
示例11: LuaFunction
public LuaFunction(SharpLua.Lua.lua_CFunction function, LuaInterface interpreter)
{
_Reference = 0;
this.function = function;
_Interpreter = interpreter;
}
示例12: getAsNetObject
public object getAsNetObject(SharpLua.Lua.LuaState luaState, int stackPos)
{
object obj = translator.getNetObject(luaState, stackPos);
if (obj == null && LuaDLL.lua_type(luaState, stackPos) == LuaTypes.LUA_TTABLE)
{
if (LuaDLL.luaL_getmetafield(luaState, stackPos, "__index"))
{
if (LuaDLL.luaL_checkmetatable(luaState, -1))
{
LuaDLL.lua_insert(luaState, stackPos);
LuaDLL.lua_remove(luaState, stackPos + 1);
obj = translator.getNetObject(luaState, stackPos);
}
else
{
LuaDLL.lua_settop(luaState, -2);
}
}
}
return obj;
}
示例13: getAsFunction
private object getAsFunction(SharpLua.Lua.LuaState luaState, int stackPos)
{
return translator.getFunction(luaState, stackPos);
}
示例14: checkudata_raw
private static object checkudata_raw(SharpLua.Lua.LuaState L, int ud, string tname)
{
object p = SharpLua.Lua.lua_touserdata(L, ud);
if (p != null)
{ /* value is a userdata? */
if (SharpLua.Lua.lua_getmetatable(L, ud) != 0)
{
bool isEqual;
/* does it have a metatable? */
SharpLua.Lua.lua_getfield(L, (int)LuaIndexes.LUA_REGISTRYINDEX, tname); /* get correct metatable */
isEqual = SharpLua.Lua.lua_rawequal(L, -1, -2) != 0;
// NASTY - we need our own version of the lua_pop macro
// lua_pop(L, 2); /* remove both metatables */
SharpLua.Lua.lua_settop(L, -(2) - 1);
if (isEqual) /* does it have the correct mt? */
return p;
}
}
return null;
}
示例15: luaL_where
//[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
public static void luaL_where(SharpLua.Lua.LuaState luaState, int level)
{
SharpLua.Lua.luaL_where(luaState, level);
}