lua study notes 3 - lua c # to interact with the (unfinished)

LuaInterface C # is connected to the bridge and Lua

LuaInterface is an open source project, there are two internal core DLL files:
  LuaInterface.dll: operating Lua code in C # need to rely on the document;
  luanet.dll: Access C # scripts in Lua libraries need to rely on the file
two dll files are copied to the project engineering
project settings "reference" import LuaInterface.dll
two dll's properties are set to "copy if newer"

Operation:
  introducing LuaInterface namespace
  instantiate the parser object Lua [Lua code execution in C #, rely on the object]
  Lua Lua Lua new new = ();
  Lua Lua parser object operation code space
  in Lua parser object, to Lua written in the code space variables, and then read using variables
  (the vast majority of cases, the use Lua parser object directly in C #, Lua script file to load a run)

 

Lua code execution within C #:
  syntax parser object Lua .DoString ( "Lua Code");
  Note:
      DOStringReaders () method is mainly used to perform some fragment shorter Lua code
      DOStringReaders () method of the code have been executed, will be added to the Lua code space, in Lua file, you can directly access to these codes

// create a parser Lua 
Lua Lua = new new Lua (); 

// variable declarations and access lua.DoString ( " name = 'CXK' Age = 72 = address 'Beijing' " ); lua.DoString ( " Print ( name, Age, address) " ); // for loop statement lua.DoString ( @" for I = 0, 10, do. 1            Print (I)          End " ); // defined function call lua.DoString ( @" the Show function ()             Print ( 'Show Lua function')          End          the Show ()          " ); // the Table Array Declaration and Access lua.DoString("myArray = { 'AAA', 'BBB', 'CCC', 'DDD'}"); lua.DoString(@"for i = 1, table.getn(myArray), 1 do             print(myArray[i])          end"); 

Lua execute the file # C
    Lua parser object .DoFile ( "[path] file Lua .lua") lua file encoding remember to UTF-8 or ANSI

= Lua Lua new new Lua (); 
lua.DoFile ( " xxx.lua " ); 
        
// the GetString () takes the data string in Lua 
lua.GetString ( " name " ); 

// getNumber () takes the value data Lua 
lua .GetNumber ( "Age" ); 

// getFunction take the function in Lua, just write function name 
LuaFunction luaShow = lua.GetFunction ( " Show " ); 
luaShow.Call (); // execute lua functions in the 
LuaFunction add = lua.GetFunction ( " the Add " ); 
System.Object [] obj = add.Call ( 10 , 20 is );

 

Guess you like

Origin www.cnblogs.com/xianguoguo/p/11482158.html