a lua table into an array
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

a lua table into an array

Started by andrea.vermetti, 26 May, 2005, 10:51:39

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

andrea.vermetti

Hello people!!!!

I need a little help!!!!

How can get form a LUA FILE a teble and put it into an array

of string  in my C# class

string[] sss = xxxx["tableLua"].to String();


???


 

Dessamator

hmmm, in lua a table is almost like an array so it wouldnt change much! but then u want to convert it to a string? well, each item has it value in the array or table, so u can convert it easily just use tostring(xxx["tablelua"])
Ignorance is Bliss.

andrea.vermetti

Thanck you!!!!!,,, i'm goin' to try!!!!!!!

andrea.vermetti

I get the table with this object (LuaInterface.LuaTable)

LuaInterface.LuaTable AWWAW= pluto.GetTable("a");

i get my table from lua file and now it becomes a c# objet....

so....

how can i test the lenght of AWWAW????

AWWAW.lenght();  it does not work
AWWAW.size();  it does not work


how can i get the AWWAW items and put them in my array

String[] str = new String[];

for (int i = 0, to  (AWWAW.lenght-1), i++)
{
 str  =  AWWAW(i)

}

HELP ME PLEASE!!!!!!!!!!!!

Optimus

Hi i'm using simulair code in my menu for robocop. So i know what ya mean or looking for, but i'm writting it in VB.Net so i can't tell ya how it should look in C#

I will ask some 1 else to help you...

Darn she got a lovely smile  :D

Laterss Optimus

andrea.vermetti

I'm using .net but in c# not vb...


how can i do the thinghs i'm doin with vb. dotnet????

how do you import lua DLLs?????

help me please....

if i could use vb......


i'm loosing a lot of time with c# (java)....

somebody say that's java is better......

HELP!!!!!!!!!!!!!

Optimus

QuoteI'm using .net but in c# not vb...


how can i do the thinghs i'm doin with vb. dotnet????

how do you import lua DLLs?????

help me please....

if i could use vb......


i'm loosing a lot of time with c# (java)....

somebody say that's java is better......

HELP!!!!!!!!!!!!!
' Import the LUA interface
Imports LuaInterface
Imports System.IO

Public Class frmRobocop
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Private LUA As LUA

    Private Sub frmRobocop_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Intialize the Lua interface
        LUA = New Lua

        'Open LUA libraries
        LUA.OpenBaseLib()
        LUA.OpenDebugLib()
        LUA.OpenIOLib()
        LUA.OpenMathLib()
        LUA.OpenStringLib()
        LUA.OpenTableLib()

        Try
            'Dofile our needed files/tables
            LUA.DoFile(Application.StartupPath + "\system\robocoplua.lua") 'Store you lua code in here that can be called for later use
            LUA.DoFile(Application.StartupPath + "\settings.tbl")
            LUA.DoFile(Application.StartupPath + "\tbl\scriptlevel.tbl")
            ''LUA.DoFile(Application.StartupPath + "\tbl\inbuildlevel.tbl")
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

        'Register object for use in lua
        LUA("TextBox_Txt") = TextBox_Txt

        'Trigger LUA event, called StartRoboCopLUA (this function is in my case stored in the file robocoplua.lua)
        Try
            LUA.GetFunction("StartRoboCopLUA").Call()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
This gives you an idea what can be done

- Optimus

kepp

The LUA.NET package is great..
The only thing i miss of it is iteration of tables etc..

You must know position or key to enter value in table from C#

You use LuaTable LT = LUA.GetTable("MyTable");
now you enter it with LT[Number] or LT[Key]

If you really want to iterate over a table i recomend you to register a C# Array to LUA;

Create the C# Array and register it with LUA["MyCArray"] = ArrayObject;

now, you can write code with LUA.Dostring();
Iterate the table you want and insert it to the C# Array

for i,v in MyLuaTable do
   MyCArray:Add(v)
end
return 1;

Upon return 1 you are ready to access the content.
Just play around, you will figure it out somehow and eventually it will be clearer to you what i mean
Guarding    

CaSaNoVa

Andrea ma sei la gnocca in foto? :D

NightLitch

Kepp that is not the right way to seduse a lady you know.

btw mate your KEY will never fit...  :D

Btw: Are you really a girl andrea.vermetti

I want to now so I can keep messing with kepp.  :P

LoooooL // NL
//NL

kepp

#10
[COLOR=green]/* Open needed libraries */[/COLOR]

	Lua LUA = new Lua();
	LUA.OpenBaseLib();
	LUA.OpenMathLib();
	...
	...
[COLOR=green]
	/*
		To register the objUser class with LUA first intialize it then
		decide name for it to use in lua:
	*/[/COLOR]
	
	LUA["Sexbomb"] = objUser;

[COLOR=green]
	/* The code below show you how this class can be used within LUA */[/COLOR]
	
	Sexbomb.sPhonenumber = Sexbomb:AskPhoneNumber()
	Sexbomb.sAddress = Sexbomb:AskAddress();
	Sexbomb.bBiggyBoob = Sexbomb:AskBoobs();


private class objUser
{
	private string mstrPhoneno = null;
	private string mstrAddress = null;
	private bool   mboolBigbo = false;

	[COLOR=green]/* Some class properties */[/COLOR]
	public string sPhonenumber
	{
		get {return mstrPhoneno;}
		set {mstrPhoneno = value;}
	}

	public string sAddress
	{
		get {return mstrAddress;}
		set {mstrAddress = value;}
	}

	public bool bBiggyBoob
	{
		get {return mboolBigbo;}
		set {mboolBigbo = value;}
	}

	[COLOR=green]/* Class function */[/COLOR]
	public string AskPhonenumber()
	{
		Console.WriteLine("What is your phone number??");
		return Console.ReadLine();
	}

	public string AskAddress()
	{
		Console.WriteLine("What is your address?");
		return Console.ReadLine();
	}

	public bool AskBoobs()
	{
		Console.WriteLine("Are they big?");
		return Convert.ToBoolean(Console.ReadLine());
	}
}

[COLOR=green]
/* 
	To get tables from LUA you should use LuaTable class.
	Problem is that you cannot iterate over the table elements with this class!
	I just came up with a solution to this problem which will return a lua table as
	an Hashtable in C#
*/
[/COLOR]


function Hashtable GetLUATable(string Tablename)
{
	Hashtable tmp = new Hashtable();
	LUA["Hashtable"] = tmp; [COLOR=green]// Register out temp Hashtable to LUA[/COLOR]

	[COLOR=green]// Put values in table into Hashtable[/COLOR]
	LUA.DoString("for i,v in " + Tablename + " do " +
		     "Hashtable:Add(i,v) " +
		     "end")

	LUA["Hashtable"] = null; [COLOR=green]// Converted to nil[/COLOR]
	return tmp;
}

[COLOR=green]
/* 	Now you have a returned Hashtable, were you can iterate over both Index and Keys. 
	the Hashtable is accessed from System.Collections..
	I havwe not tested above function but should perform the task
*/
[/COLOR]

****
GetLUATable function shall be C# function so change to C#
Guarding    

6Marilyn6Manson6

Andrea molto gnocca complimenti :D

CaSaNoVa

Sperando ke sia lei eh^_^

andrea.vermetti

Thank you everybody!!!!!!

You resolved all my trubles!!!!!


KISSES


for italian kids.....

yes i'm pretty girl from Reggio Emilia!!!!

CaSaNoVa

Hi Andrea^_^

I knew you're a pretty italian girl^_^

Post me if u want speake about ptokax and scripts ;)

kepp

Yea or me...
PM me and i'll ya anything you want to know ;)
Guarding    

SMF spam blocked by CleanTalk