Inthiscase, I'm goingtobeusingLuisbecause, likeLouis, itintegrateswith c++ verywell.
Andit's a veryquicklanguage, andit's alsosenttactically, quitesimple.
Thepracticeofusingscriptstowardmentorprogramsisgettingmoreandmorecommon, particularlyinthegamingworld, wherethemodificationofgamesisactuallybecoming a businessinitsownright.
ShemaywanttoinstallLuisto a knownlocationonalwaysreferencedthatoneinstanceofLouisLouis, fundamentally a C library.
So I needtotellthecompilethat I'm goingtobedealingwith C definedfunctions.
I dothatusingtheexturnkeyword.
Andthen I'm goingtoincludethelooaheadoffasters I needdirectlyreferencedtothelocalLou a 535 pathofthevisualstudioproject.
Afterwe'veincludedtheheadoffilesweneedtolinktothelibrarynowinWindowsandVisualStudio, I canusethehashpragmatistforthiswillbelotsofpeoplecomplainingaboutthatbecausenotallcompilerssupportedsomeguardingitwithWin 30 tothisapproachsavesmefromhavingtoalteranyoftheprojectpropertiesdirectly.
Dependingonthebuildingtoolchainthatyou'reusing, youmayneedtoincludeadditionaldirectivestothecompilertoelinkedtothislibrary, andthat's it.
That's allweneedtostartusingLuis.
OneofthenicethingsaboutLouisisitdoesn't reallygetcompileduntilyouneedit, soitalwaysexistsin a nicetextformon.
Andthereareotherthings, too, regardingtheinformationtransferredfromthe C plusplustoMaytothescriptinglanguagetoMay, andwe'lllookatthatin a bitmoredetaillater.
I willgothroughwhattheLouisstackisin a minute, butrightnow, juststaywithme.
Assumingthescriptdidexecutesuccessfully, wewanttogetthevalue A fromourcommand.
Well, inthiscaseexistsgloballywithintheloo, a virtualmachine.
So I'm goingtousetheglueitgetglobalfunctiontogivemeaccesstothevariable, eh?
Onhereinlies.
Anotherroundofvalidation.
I don't knowwhattype A isbluerfundamentallyisreasonablytypelis.
Thisisverydifferentto C pluspluswhereeverythingisquiteexplicitlydefined, whatitisandhowit's storedinmemory.
Now I amexpectingtheresult.
A tobe a number.
Andso I'm goingtotestexplicitly.
Isit a number?
Andagain, weseethisstrangenotationon I willdescribewhatthatisin a minute, knowingthat a isnowdefinitely a number, I canreasonablysafelyconvertitto a C plusplusfloattohear I'vecreated a variable a in c++ on I'veusedtheLouistonumberCommandtoconvertwhatever a waasinto a numberand I'm castingittoafloat.
I'm nowjustgoingtooutputthatvaluetothecouncil.
Nowthere's a furtherlittlebitofhousekeepingtodobeforepeoplestartwritinginandcomplaining.
Wheneverwe'vecreated a luavirtualmachine, weshouldalsocleanitup.
Wecanusetheloo a closefunction.
Todothatonthiswillmakepeoplereallyangry.
I'm alsogoingtothrowin a systempausejustbecauseitmakesmakingthevideoofiteasier.
Soherewe'vegot a simpleprogram.
Wetake a command A equalssevenplus 11.
Wecreate a luavirtualmachineandwetellittoexecutethatcommandwithincheck.
Diditsuccessfullyexecutethecommand?
Andifitdid, wetryandextractthevalue A as a numbersowecandisplayitin C++.
Ifitdidn't successfullyexecutethecommand, then I'm goingtodisplayanyerrormessagesthattheloo a virtualmachinehasreturned.
I thenaskedLouistogoanddirectlyconvertitscontentsofthatboxto a numberthat C pluspluscanunderstand.
Whenweputthesyntaxerrorintothecommand, itdidn't knowhowtoexecutethecommand, anditplacedanerrormessageas a stringonthetopofthestack.
I wouldn't blameyouforthinkingwell, sowhat?
Thesourceseemslike a lotofefforttoadd 7 to 11 butLouisactuallyquite a powerfulandwellsupportedlanguage, sowecanusemorecomplicatedfunctionswithintheframework.
Solet's say I wantedtotakethesinefunctionoffsomevalue.
Now a naiveapproachistoduplicatethisforallofthedifferentfields.
So I justmodifiedtheprogramtoreadinallofthosesettings, I onlyseeSquireKieranofwewilllevel 20 and I don't think I evenneedtodemonstratethatif I changethesesettings, thestringwillchangeinthesequenceplusprogram.
SousingLouissimply a configurationfileforsomethingisquitesimple, butitdidseem a littleinvolved.
There's a lotofefforttogototheirjusttoextractthedatathatyou'relookingfornow.
Soinsteadofdefiningallofthepropertiesof a playerobjectindividually, let's actuallycreate a playerobjectonLouarebeingluredtheseveralwaystogoaboutdoingthis.
So a simpleoneisusingkeyandvaluepairs.
Solet's giveitthekeytitleandgiveitthevalue.
WhatwehaveherestartstodemonstratethepowerofLouis.
We'veeffectivelycreated a boxcalledTitleandgiventheboxcontentsofSquireon.
We'veputthatboxinanoverallboxcalledPlayer.
Louhasadditionalwaysofreachingthesamegoal.
Solet's have a lookhowweinterrogatethisglobalobjectplayertogetthecontentsand I'lljustcommenttheseout.
Well, startingatthetopofour C pluspluscode, weknowthatplayernameisnolongerwhatwe'relookingfor.
Whatwe'relookingforis a globalobjectcalledplayerNowplayer, aswedefineditisnolongersimpletype.
It's actually a tablecontainingnamesandvalues.
So I'm goingtomakesurethattheglobalitisfoundisinfact a table.
Andjusttokeepthingsclear, I'm goingtoremovethepreviouscodetofind a particularelementin a table.
WeneedtoaddthenameofthatelementtotheLewisstack, so I'm goingtousetheloo.
If I choosenottopopthevalueoffthestack, I canstilldothings.
I justhavetomaintaintheindicesproperly.
Thiscouldgetquitecomplicatedwhenworkingwithlargestructuresandstructureswithnestedstructures, so I findit's alwaysbettertomaintainyourstackatthemicrolevelratherthanthemacrolevel.
Thismeans I couldcouldn't pastethesamecodenowtogettheotherelementsofthestructure I'm lookingfor.
Andyoumaynotice, I canalsodothingsoutoforderbecause I'm doing a keyvaluesearcheachtime.
Theoldoneoutis, ofcourse, level.
Eventhoughthekeyis a string, thevaluerexpectingisaninterviewjustbeforerunit a quickreminderofwhattheoriginalscriptlookslikeon I'llClickPlay.
Andofcourse, weseetheresultthatweexpect.
Sofarwe'velookedatverysimplemethodstoextractinformationfrom a loofileon.
Theycanget a lotmorecomplicatedthanwhat I'veshownhereagain.
I wouldbegoodtobeabletocallfunctionsinLouisfromoursecretscloseprogram, solet's have a lookatjustthat.
Fornow.
I'm goingtocommentoutthiscodebecause I wanttoreuseitlater.
I'm goingtogobacktomyLouisscriptsand I canleavethat I'm goingtocreate a function I'm goingtocallit, andstuffonthefunctionisjustgoingtotaketwovariables.
That, too, howmanyargumentswereexpectinginreturnonthefinalargumentis a littlebitmoreadvancedthat's actuallyusedtodefinehowourerrorshandledwithintheLouisscript, andwemightlookatthatin a laterpartinthisseries.
So, in a similarway, thedofilefunctionhasexecutedthewholescript, The P.
Youcouldevengo a SWfartomakeyour C programsensitivetothistextfilechanging, althoughthat's quiteanadvancedthingtodo, mightleavethatalsofor a latervideo.
NowwecancallfunctionsinLewis.
WecanleanonLuistostartdoingmorecomplicatedthings, Solet's have a getplayfunctionintowhichwepassanindex.
I'vemodifiedtheLouisscripttocontain a smalldatabaseofftheplayersandadded a getplayerfunctiontoreturntheplayerat a specificindexinthe c++ code.
ButsometimesLouismayneedtocallfunctionsoffthehostenvironment c++ environmentsinthiscase.
Solet's take a lookatthat.
I'm goingtocreateanadditionalLouisfunction.
I'm goingtocallitdo a thing, andit's goingtotaketwoparameters A and B, so I canreuse a littlebitofthecode I'vegotalreadyandaskedbefore I'm goingtomakeitprintoutthefactthatit's beencalledjustsowecankeeptrack.
Butthen I wantedtocall a functioninthe C plusplusenvironment.
I don't have a nameforthisfunctionyet, but I'm justgoingtocreate a variable.
See, I'm goingtocallithostFunctionToe, which I'm goingtopassintheparameters A and B.
Soitdoesseem a littlebitredundantthatwe'recreatingarguments A and B in C programpassingthemtoLowerLouis, thenpassesthembacktotheseaprogram.
What I willaddtothisis a littleoutputjustsowecankeeptrackofwerethingswereuptosowecanseehostfunctionhasbeencold, andthen I'm goingtocalculatetheresultinthiscase, a simplemultiply.
I thenwanttopushbackontotheLouisstack, theresultwiththelowerpushnumberfunction, andas I mentionedearlier, I'm onlypushingonethingontothestack.
Sothat's thevaluethat I'm returningone.
Sothisisgreat.
We'venowdefined a functionin C++.
WeneedtolinkittothevirtualmachineandLou, a veryconvenientlyprovides a routineforustodothat.
LouisRegisteron, innit?
I provide a stringname.
Sothat's whatLouwillactuallyusetocallthefunction.
And I provide a functionpointertothefunctionthatwe'vedefined, andthat's allweneedtodo.
Sointheareawherewe'vecalledtheoriginaldo a thingfunction, let's displaywhattheultimateresultisandseeifallofthisworks.
Sothefirstthingthat's happenedisthedo a thing.
FunctioninLouwascalledwiththeValuesfiveandsix.
Thatfunctionthenwentontocallhostfunctionwiththevalues 15 and 18.
Beingabletoenhanceyourprogramsfunctionalityis a reallycoolthingtodo, certainlywhenyoucanstopcreatinggamesandapplicationsthatcanbemodifiedbyotherpeople.
Andthat's exactlywhy I wantedtoincludethisvideobeforegoingtothenextpartofmytopdown, citybasedcarcryinggame, Siri's, because I amactuallygoingtobeusingLuistohandlegamesettingsonmissionbasedoperationsinthatapplication.
Butyoumayhavenoticedthatthisvideoisalsoattackedwiththeominoushashoneinimplyingthatit's partofthelargestSiri's and I thinkitwillbe, though I don't knowwhattheschedulewillbebecausethere's a lotmorecoolstuffyoucandowithLouand C plusplus.