Skip to content

Commit

Permalink
+void lua_pushcfunction (lua_State *L, lua_CFunction f); /Lua 5.1; …
Browse files Browse the repository at this point in the history
…5.2; 5.3

+`void lua_arith (lua_State *L, int op);` /Lua 5.2; 5.3
+`const char *lua_tostring (lua_State *L, int index);` /5.1, 5.2, 5.3
+`void lua_insert (lua_State *L, int index);` /Lua 5.1; 5.2; 5.3
+`void lua_remove (lua_State *L, int index);` /Lua 5.1; 5.2; 5.3
+`void lua_replace (lua_State *L, int index);` / Lua 5.1; 5.2; 5.3
+`void lua_register (lua_State *L, const char *name, lua_CFunction f);` /Lua 5.1; 5.2; 5.3
+`size_t lua_rawlen (lua_State *L, int index);` /Lua 5.2; 5.3
+`size_t lua_objlen (lua_State *L, int index);` /Lua 5.1

Added forgotten declaration for 5.2 & 5.3: +`int lua_pushthread (lua_State *L);`
  • Loading branch information
3F committed Jan 30, 2019
1 parent 7376a58 commit 44f4091
Show file tree
Hide file tree
Showing 6 changed files with 498 additions and 22 deletions.
108 changes: 108 additions & 0 deletions LuNari/API/Lua51/Func51.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,39 @@ public void pushcclosure(LuaState L, LuaCFunction fn, int n)
bind<Action<LuaState, LuaCFunction, int>>("pushcclosure")(L, fn, n);
}

/// <summary>
/// [-0, +1, m] void lua_pushcfunction (lua_State *L, lua_CFunction f);
///
/// Pushes a C function onto the stack. This function receives a pointer to a C function
/// and pushes onto the stack a Lua value of type function that, when called, invokes the corresponding C function.
///
/// Defined as a macro:
/// #define lua_pushcfunction(L,f) lua_pushcclosure(L,f,0)
/// </summary>
/// <param name="L"></param>
/// <param name="f"></param>
public virtual void pushcfunction(LuaState L, LuaCFunction f)
{
pushcclosure(L, f, 0);
}

/// <summary>
/// [-0, +0, e] void lua_register (lua_State *L, const char *name, lua_CFunction f);
///
/// Sets the C function f as the new value of global name.
///
/// Defined as a macro:
/// #define lua_register(L,n,f) (lua_pushcfunction(L, f), lua_setglobal(L, n))
/// </summary>
/// <param name="L"></param>
/// <param name="name"></param>
/// <param name="f"></param>
public void register(LuaState L, string name, LuaCFunction f)
{
pushcfunction(L, f);
setglobal(L, name);
}

/// <summary>
/// [-1, +0, e] void lua_setfield (lua_State *L, int index, const char *k);
///
Expand Down Expand Up @@ -108,6 +141,24 @@ public LuaNumber tonumber(LuaState L, int index)
return bind<Func<LuaState, int, LuaNumber>>("tonumber")(L, index);
}

/// <summary>
/// [-0, +0, m] const char *lua_tostring (lua_State *L, int index);
///
/// Equivalent to lua_tolstring with len equal to NULL.
/// </summary>
/// <param name="L"></param>
/// <param name="index"></param>
/// <returns>
/// Returns a fully aligned pointer to a string inside the Lua state.
/// This string always has a zero ('\0') after its last character (as in C), but can contain other zeros in its body.
/// Because Lua has garbage collection, there is no guarantee that the pointer returned by lua_tolstring will be valid
/// after the corresponding value is removed from the stack.
/// </returns>
public CharPtr tostring(LuaState L, int index)
{
return bind<Func<LuaState, int, IntPtr>>("tostring")(L, index);
}

/// <summary>
/// [-0, +0, m] const char *lua_tolstring (lua_State *L, int index, size_t *len);
///
Expand Down Expand Up @@ -184,6 +235,45 @@ public int gettop(LuaState L)
return bind<Func<LuaState, int>>("gettop")(L);
}

/// <summary>
/// [-1, +1, -] void lua_insert (lua_State *L, int index);
///
/// Moves the top element into the given valid index, shifting up the elements above this index to open space.
/// Cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position.
/// </summary>
/// <param name="L"></param>
/// <param name="index"></param>
public void insert(LuaState L, int index)
{
bind<Action<LuaState, int>>("insert")(L, index);
}

/// <summary>
/// [-1, +0, -] void lua_remove (lua_State *L, int index);
///
/// Removes the element at the given valid index, shifting down the elements above this index to fill the gap.
/// Cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position.
/// </summary>
/// <param name="L"></param>
/// <param name="index"></param>
public void remove(LuaState L, int index)
{
bind<Action<LuaState, int>>("remove")(L, index);
}

/// <summary>
/// [-1, +0, -] void lua_replace (lua_State *L, int index);
///
/// Moves the top element into the given position (and pops it), without shifting any element
/// (therefore replacing the value at the given position).
/// </summary>
/// <param name="L"></param>
/// <param name="index"></param>
public void replace(LuaState L, int index)
{
bind<Action<LuaState, int>>("replace")(L, index);
}

/// <summary>
/// [-0, +1, -] void lua_pushvalue (lua_State *L, int index);
///
Expand Down Expand Up @@ -445,5 +535,23 @@ public int type(LuaState L, int index)
{
return bind<Func<LuaState, int, int>>("type")(L, index);
}

/// <summary>
/// [-0, +0, -] size_t lua_objlen (lua_State *L, int index);
///
/// Returns the "length" of the value at the given acceptable index.
/// </summary>
/// <param name="L"></param>
/// <param name="index"></param>
/// <returns>
/// for strings, this is the string length;
/// for tables, this is the result of the length operator ('#');
/// for userdata, this is the size of the block of memory allocated for the userdata;
/// for other values, it is 0.
/// </returns>
public size_t objlen(LuaState L, int index)
{
return bind<Func<LuaState, int, size_t>>("objlen")(L, index);
}
}
}
100 changes: 94 additions & 6 deletions LuNari/API/Lua51/ILua51.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,32 @@ public interface ILua51: ILevel
/// <param name="n">The maximum value is 255.</param>
void pushcclosure(LuaState L, LuaCFunction fn, int n);

/// <summary>
/// [-0, +1, m] void lua_pushcfunction (lua_State *L, lua_CFunction f);
///
/// Pushes a C function onto the stack. This function receives a pointer to a C function
/// and pushes onto the stack a Lua value of type function that, when called, invokes the corresponding C function.
///
/// Defined as a macro:
/// #define lua_pushcfunction(L,f) lua_pushcclosure(L,f,0)
/// </summary>
/// <param name="L"></param>
/// <param name="f"></param>
void pushcfunction(LuaState L, LuaCFunction f);

/// <summary>
/// [-0, +0, e] void lua_register (lua_State *L, const char *name, lua_CFunction f);
///
/// Sets the C function f as the new value of global name.
///
/// Defined as a macro:
/// #define lua_register(L,n,f) (lua_pushcfunction(L, f), lua_setglobal(L, n))
/// </summary>
/// <param name="L"></param>
/// <param name="name"></param>
/// <param name="f"></param>
void register(LuaState L, string name, LuaCFunction f);

/// <summary>
/// [-1, +0, e] void lua_setfield (lua_State *L, int index, const char *k);
///
Expand Down Expand Up @@ -87,6 +113,21 @@ public interface ILua51: ILevel
/// <returns></returns>
LuaNumber tonumber(LuaState L, int index);

/// <summary>
/// [-0, +0, m] const char *lua_tostring (lua_State *L, int index);
///
/// Equivalent to lua_tolstring with len equal to NULL.
/// </summary>
/// <param name="L"></param>
/// <param name="index"></param>
/// <returns>
/// Returns a fully aligned pointer to a string inside the Lua state.
/// This string always has a zero ('\0') after its last character (as in C), but can contain other zeros in its body.
/// Because Lua has garbage collection, there is no guarantee that the pointer returned by lua_tolstring will be valid
/// after the corresponding value is removed from the stack.
/// </returns>
CharPtr tostring(LuaState L, int index);

/// <summary>
/// [-0, +0, m] const char *lua_tolstring (lua_State *L, int index, size_t *len);
///
Expand All @@ -95,16 +136,18 @@ public interface ILua51: ILevel
/// The Lua value must be a string or a number; otherwise, the function returns NULL.
/// If the value is a number, then lua_tolstring also changes the actual value in the stack to a string.
/// (This change confuses lua_next when lua_tolstring is applied to keys during a table traversal.)
///
/// lua_tolstring returns a fully aligned pointer to a string inside the Lua state.
/// This string always has a zero ('\0') after its last character (as in C), but can contain other zeros in its body.
/// Because Lua has garbage collection, there is no guarantee that the pointer returned by lua_tolstring will be valid
/// after the corresponding value is removed from the stack.
/// </summary>
/// <param name="L"></param>
/// <param name="index">Lua value at the given acceptable index.</param>
/// <param name="len">string length</param>
/// <returns></returns>
/// <returns>
/// Returns a fully aligned pointer to a string inside the Lua state.
/// This string always has a zero ('\0') after its last character (as in C),
/// but can contain other zeros in its body.
///
/// Because Lua has garbage collection, there is no guarantee that the pointer returned by lua_tolstring
/// will be valid after the corresponding value is removed from the stack.
/// </returns>
CharPtr tolstring(LuaState L, int index, out size_t len);

/// <summary>
Expand Down Expand Up @@ -148,6 +191,36 @@ public interface ILua51: ILevel
/// <returns>the index of the top element in the stack.</returns>
int gettop(LuaState L);

/// <summary>
/// [-1, +1, -] void lua_insert (lua_State *L, int index);
///
/// Moves the top element into the given valid index, shifting up the elements above this index to open space.
/// Cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position.
/// </summary>
/// <param name="L"></param>
/// <param name="index"></param>
void insert(LuaState L, int index);

/// <summary>
/// [-1, +0, -] void lua_remove (lua_State *L, int index);
///
/// Removes the element at the given valid index, shifting down the elements above this index to fill the gap.
/// Cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position.
/// </summary>
/// <param name="L"></param>
/// <param name="index"></param>
void remove(LuaState L, int index);

/// <summary>
/// [-1, +0, -] void lua_replace (lua_State *L, int index);
///
/// Moves the top element into the given position (and pops it), without shifting any element
/// (therefore replacing the value at the given position).
/// </summary>
/// <param name="L"></param>
/// <param name="index"></param>
void replace(LuaState L, int index);

/// <summary>
/// [-0, +1, -] void lua_pushvalue (lua_State *L, int index);
///
Expand Down Expand Up @@ -361,5 +434,20 @@ public interface ILua51: ILevel
/// LUA_TUSERDATA, LUA_TTHREAD, and LUA_TLIGHTUSERDATA.
/// </returns>
int type(LuaState L, int index);

/// <summary>
/// [-0, +0, -] size_t lua_objlen (lua_State *L, int index);
///
/// Returns the "length" of the value at the given acceptable index.
/// </summary>
/// <param name="L"></param>
/// <param name="index"></param>
/// <returns>
/// for strings, this is the string length;
/// for tables, this is the result of the length operator ('#');
/// for userdata, this is the size of the block of memory allocated for the userdata;
/// for other values, it is 0.
/// </returns>
size_t objlen(LuaState L, int index);
}
}
40 changes: 40 additions & 0 deletions LuNari/API/Lua52/Func52.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,26 @@ public CharPtr pushstring(_.LuaState L, string s)
return bind<Func<_.LuaState, string, IntPtr>>("pushstring")(L, s);
}

/// <summary>
/// [-(2|1), +1, e] void lua_arith (lua_State *L, int op);
///
/// Performs an arithmetic operation over the two values
/// (or one, in the case of negation) at the top of the stack,
/// with the value at the top being the second operand, pops these values,
/// and pushes the result of the operation.
///
/// The function follows the semantics of the corresponding Lua operator
/// (that is, it may call metamethods).
/// </summary>
/// <param name="L"></param>
/// <param name="op">
/// Must be one of the following constants: LuaH.LUA_OP...
/// </param>
public void arith(LuaState L, int op)
{
bind<Action<LuaState, int>>("arith")(L, op);
}

/// <summary>
/// [-0, +1, e] void lua_getglobal (lua_State *L, const char *name);
///
Expand All @@ -75,5 +95,25 @@ public override void getglobal(LuaState L, string name)
{
bind<Action<LuaState, string>>("getglobal")(L, name);
}

/// <summary>
/// [-0, +0, –] size_t lua_rawlen (lua_State *L, int index);
///
/// Returns the raw "length" of the value at the given index.
///
/// Note: lua_objlen (5.1) was renamed lua_rawlen (5.2)
/// </summary>
/// <param name="L"></param>
/// <param name="index"></param>
/// <returns>
/// for strings, this is the string length;
/// for tables, this is the result of the length operator ('#') with no metamethods;
/// for userdata, this is the size of the block of memory allocated for the userdata;
/// for other values, it is 0.
/// </returns>
public size_t rawlen(LuaState L, int index)
{
return bind<Func<LuaState, int, size_t>>("rawlen")(L, index);
}
}
}
Loading

0 comments on commit 44f4091

Please sign in to comment.